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

📄 report.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void addDesc(Entity entity) {        add(entity.getShortName(), true);        add(entity.getOwner().getName());    }    /**     * Internal method.  Not for typical use.     * <p>     * Tests wheter the data value at the given index has been marked     * as obscured.     *     * @param index position of data value (indexes are chronological     * and start at zero)     * @return true if the data value was marked obscured     */    public boolean isValueObscured(int index) {        if (this.obscuredIndexes.get(new Integer(index)) == null)            return false;        return true;    }    /**     * Internal method.  Not for typical use.     * <p>     * Remove the data value from the report.  This operation is     * irreversible.     *     * @param index position of data value (indexes are chronological     * and start at zero     */    public void hideData(int index) {        this.tagData.setElementAt(null, index);    }    /**     * Indent the report.     */    public void indent() {        indent(1);    }    /**     * Indent the report <i>n</i> times.     *     * @param n the number of times to indent the report     */    public void indent(int n) {        this.indentation += (n * Report.DEFAULT_INDENTATION);    }    /**     * Internal method.  Not for typical use.     * <p>     * Get the total number of data values associated with this     * report.  Note that this includes the <code>true/false</code>     * values added for &lt;msg&gt; tags as well.     *     * @return the number of data values     */    public int dataCount() {        return this.tagData.size();    }    private String getTag() {        return getTag(this.tagCounter);    }    private String getTag(int index) {        try {            String value = (String)this.tagData.elementAt(index);            if (value == null) {                return Report.OBSCURED_STRING;            }			return value;        } catch (ArrayIndexOutOfBoundsException e) {            System.out.println("Error: Report#getText --> Array Index out of Bounds Exception (index: " + index + ") for a report with ID " + this.messageId + ".  Maybe Report#add wasn't called enough times for the amount of tags in the message?");            return "[Reporting Error: see megameklog.txt for details]";        }    }    /**     * Get the report in its final form, with all the necessary     * substitutions made.     *     * @return a String with the final report     */    public String getText() {        //The raw text of the message, with tags.        String raw = ReportMessages.getString(String.valueOf(this.messageId));        //This will be the finished product, with data substituted for tags.        StringBuffer text = new StringBuffer();        if (raw == null) {            //Should we handle this better?  Check alternate language files?            System.out.println("Error: No message found for ID " + this.messageId);            text.append("[Reporting Error for message ID ")                .append(this.messageId).append("]");        } else {            int i = 0;            int mark = 0;            while (i < raw.length()) {                if (raw.charAt(i) == '<') {                    //find end of tag                    int endTagIdx = raw.indexOf('>', i);                    if (raw.indexOf('<', i+1) != -1 && raw.indexOf('<', i+1) < endTagIdx) {                        //hmm...this must be a literal '<' character                        i++;                        continue;                    }                    //copy the preceeding characters into the buffer                    text.append(raw.substring(mark, i));                    if (raw.substring(i+1, endTagIdx).equals("data")) {                        text.append(getTag());                        //                            System.out.println("Report-->getText(): " + this.tagData.elementAt(this.tagCounter));                        this.tagCounter++;                    } else if (raw.substring(i+1, endTagIdx).equals("list")) {                        for (int j = tagCounter; j < this.tagData.size(); j++) {                            text.append(getTag(j)).append(", ");                        }                        text.setLength(text.length() - 2); // trim last comma                    } else if (raw.substring(i+1, endTagIdx).startsWith("msg:")) {                        boolean selector = Boolean.valueOf(getTag()).booleanValue();                        if (selector) {                            text.append(ReportMessages.getString(raw.substring(i+5, raw.indexOf(',', i))));                        } else {                            text.append(ReportMessages.getString(raw.substring(raw.indexOf(',', i)+1, endTagIdx)));                        }                    } else if (raw.substring(i+1, endTagIdx).equals("newline")) {                        text.append("\n");                    } else {                        //not a special tag, so treat as literal text                        text.append(raw.substring(i, endTagIdx + 1));                    }                    mark = endTagIdx + 1;                    i = endTagIdx;                }                i++;            }            text.append(raw.substring(mark));            handleIndentation(text);            text.append(getNewlines());        }        this.tagCounter = 0;        //debugReport        if (this.type == Report.TESTING) {            Report.mark(text);        }        return text.toString();    }    private void handleIndentation(StringBuffer sb) {        if (this.indentation == 0 || sb.length() == 0)            return;        int i = 0;        while (sb.charAt(i) == '\n') {            i++;            if (i == sb.length())                continue;        }        sb.insert(i,getSpaces());    }    private String getSpaces() {        StringBuffer spaces = new StringBuffer();        for (int i = 0; i < this.indentation; i++) {            spaces.append(" ");        }        return spaces.toString();    }    private String getNewlines() {        StringBuffer sbNewlines = new StringBuffer();        for (int i = 0; i < this.newlines; i++) {            sbNewlines.append("\n");        }        return sbNewlines.toString();    }    /**     * Adds a newline to the last report in the given Vector.     *     * @param v a Vector of Report objects     */    public static void addNewline(Vector v) {        ((Report) v.elementAt(v.size() - 1)).newlines++;    }    /**     * Internal method.  Not for typical use.     * <p>     * Adds the given player name to the report's list of players who     * received an obscured version of this report from the server at     * some time in the past.     *     * @param playerName the String containing the player's name     */    public void addObscuredRecipient(String playerName) {        this.obscuredRecipients.addElement(playerName);    }    /**     * Internal method.  Not for typical use.     * <p>     * Tests whether the given player name is on the report's list of     * players who received an obscured version of this report from     * the server at some time in the past.     *     * @param playerName the String containing the player's name     * @return true if the player was sent an obscured version of this report     */    public boolean isObscuredRecipient(String playerName) {        for (int i = 0; i < this.obscuredRecipients.size(); i++) {            String s = (String)this.obscuredRecipients.elementAt(i);            if (s.equals(playerName)) {                return true;            }        }        return false;    }    /**     * Useful for debugging purposes.     *     * @return a String of the form "Report(messageId=n)"     */    public String toString() {        String val = new String();        val = "Report(messageId=";        val += messageId;        val += ")";        return val;    }    /**     * DEBUG method - do not use     */    //debugReport method    public void markForTesting() {        this.type = Report.TESTING;    }    //debugReport method    private static StringBuffer mark(StringBuffer sb) {        sb.insert(0,"<hidden>");        int i = sb.length() - 1;        while (sb.charAt(i) == '\n') {            i--;            if (i == 0)                continue;        }        sb.insert(i+1, "</hidden>");        return sb;    }    public static void indentAll(Vector vDesc, int amount) {        // Just avoid an error condition.        if (vDesc == null)            return;        Enumeration x = vDesc.elements();        while (x.hasMoreElements()) {            Report r = (Report)x.nextElement();            r.indent(amount);        }    }}

⌨️ 快捷键说明

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