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

📄 namerecord.java

📁 介绍java核心技术的pio编程方法以及基本概念
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /** get the custom menu text     * @return custom menu text     */    public String getCustomMenuText(){        return field_14_custom_menu_text;    }    /** gets the description text     * @return description text     */    public String getDescriptionText(){        return field_15_description_text;    }    /** get the help topic text     * @return gelp topic text     */    public String getHelpTopicText(){        return field_16_help_topic_text;    }    /** gets the status bar text     * @return status bar text     */    public String getStatusBarText(){        return field_17_status_bar_text;    }    /**     * called by constructor, should throw runtime exception in the event of a     * record passed with a differing ID.     *     * @param id alleged id for this record     */    protected void validateSid(short id) {        if (id != sid) {            throw new RecordFormatException("NOT A valid Name RECORD");        }    }        /**     * called by the class that is responsible for writing this sucker.     * Subclasses should implement this so that their data is passed back in a	 * @param offset to begin writing at	 * @param data byte array containing instance data     * @return number of bytes written     */    public int serialize( int offset, byte[] data )    {        LittleEndian.putShort( data, 0 + offset, sid );        short size = (short)( 15 + getTextsLength() + getNameDefinitionSize());        LittleEndian.putShort( data, 2 + offset, size );        // size defined below        LittleEndian.putShort( data, 4 + offset, getOptionFlag() );        data[6 + offset] = getKeyboardShortcut();        data[7 + offset] = getNameTextLength();        LittleEndian.putShort( data, 8 + offset, getDefinitionLength() );        LittleEndian.putShort( data, 10 + offset, getUnused() );        LittleEndian.putShort( data, 12 + offset, getEqualsToIndexToSheet() );        data[14 + offset] = getCustomMenuLength();        data[15 + offset] = getDescriptionTextLength();        data[16 + offset] = getHelpTopicLength();        data[17 + offset] = getStatusBarLength();        data[18 + offset] = getCompressedUnicodeFlag();			int start_of_name_definition = 19 + field_3_length_name_text;			if (this.isBuiltInName()) {				//can send the builtin name directly in				data [19 + offset] =  this.getBuiltInName();			} else if ((this.getCompressedUnicodeFlag() & 0x01) == 1) {				StringUtil.putUnicodeLE( getNameText(), data, 19 + offset );				start_of_name_definition = 19 + (2 * field_3_length_name_text);			} else {				StringUtil.putCompressedUnicode( getNameText(), data, 19 + offset );			}			Ptg.serializePtgStack(field_13_name_definition,  data, start_of_name_definition + offset );            int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition;            StringUtil.putCompressedUnicode( getCustomMenuText(), data, start_of_custom_menu_text + offset );            int start_of_description_text = start_of_custom_menu_text + field_7_length_custom_menu;            StringUtil.putCompressedUnicode( getDescriptionText(), data, start_of_description_text + offset );            int start_of_help_topic_text = start_of_description_text + field_8_length_description_text;            StringUtil.putCompressedUnicode( getHelpTopicText(), data, start_of_help_topic_text + offset );            int start_of_status_bar_text = start_of_help_topic_text + field_9_length_help_topic_text;            StringUtil.putCompressedUnicode( getStatusBarText(), data, start_of_status_bar_text + offset );            return getRecordSize();        /* } */    }    /**      * Gets the length of all texts, in bytes     * @return total length     */    public int getTextsLength(){        int result;        result = getRawNameTextLength() + getDescriptionTextLength() +        	getHelpTopicLength() + getStatusBarLength();        return result;    }        private int getNameDefinitionSize() {    	int result = 0;        List list   = field_13_name_definition;                for (int k = 0; k < list.size(); k++)        {        	Ptg ptg = ( Ptg ) list.get(k);        	        	result += ptg.getSize();        }        return result;        }    /** returns the record size     */    public int getRecordSize(){        int result;        result = 19 + getTextsLength() + getNameDefinitionSize();                return result;    }    /** gets the extern sheet number     * @return extern sheet index     */    public short getExternSheetNumber(){        if (field_13_name_definition == null || field_13_name_definition.isEmpty()) return 0;        Ptg ptg = (Ptg) field_13_name_definition.peek();        short result = 0;        if (ptg.getClass() == Area3DPtg.class){            result = ((Area3DPtg) ptg).getExternSheetIndex();        } else if (ptg.getClass() == Ref3DPtg.class){            result = ((Ref3DPtg) ptg).getExternSheetIndex();        }        return result;    }    /** sets the extern sheet number     * @param externSheetNumber extern sheet number     */    public void setExternSheetNumber(short externSheetNumber){        Ptg ptg;        if (field_13_name_definition == null || field_13_name_definition.isEmpty()){            field_13_name_definition = new Stack();            ptg = createNewPtg();        } else {            ptg = (Ptg) field_13_name_definition.peek();        }        if (ptg.getClass() == Area3DPtg.class){            ((Area3DPtg) ptg).setExternSheetIndex(externSheetNumber);        } else if (ptg.getClass() == Ref3DPtg.class){            ((Ref3DPtg) ptg).setExternSheetIndex(externSheetNumber);        }    }    private Ptg createNewPtg(){        Ptg ptg = new Area3DPtg();        field_13_name_definition.push(ptg);        return ptg;    }    /** gets the reference , the area only (range)     * @return area reference     */    public String getAreaReference(Workbook book){        if (field_13_name_definition == null || field_13_name_definition.isEmpty()) return "Error";        Ptg ptg = (Ptg) field_13_name_definition.peek();        String result = "";        // If it's a union, descend in and process        if (ptg.getClass() == UnionPtg.class) {            Iterator it =field_13_name_definition.iterator();            while( it.hasNext() ) {                Ptg p = (Ptg)it.next();                String thisRes = getAreaRefString(p, book);                if(thisRes.length() > 0) {                    // Add a comma to the end if needed                    if(result.length() > 0 && !result.endsWith(",")) {                        result += ",";                    }                    // And add the string it corresponds to                    result += thisRes;                }            }        } else {            // Otherwise just get the string            result = getAreaRefString(ptg, book);        }        return result;    }    /**     * Turn the given ptg into a string, or     *  return an empty string if nothing is possible     *  for it.     */    private String getAreaRefString(Ptg ptg,Workbook book) {        if (ptg.getClass() == Area3DPtg.class){            return ptg.toFormulaString(book);        } else if (ptg.getClass() == Ref3DPtg.class){            return ptg.toFormulaString(book);        } else if (ptg.getClass() == DeletedArea3DPtg.class || ptg.getClass() == DeletedRef3DPtg.class) {        	return "#REF!";        }        return "";    }    /** sets the reference , the area only (range)     * @param ref area reference     */    public void setAreaReference(String ref){        //Trying to find if what ptg do we need        RangeAddress ra = new RangeAddress(ref);        Ptg oldPtg;        Ptg ptg;        if (field_13_name_definition==null ||field_13_name_definition.isEmpty()){            field_13_name_definition = new Stack();            oldPtg = createNewPtg();        } else {            //Trying to find extern sheet index            oldPtg = (Ptg) field_13_name_definition.pop();        }        short externSheetIndex = 0;        if (oldPtg.getClass() == Area3DPtg.class){            externSheetIndex =  ((Area3DPtg) oldPtg).getExternSheetIndex();        } else if (oldPtg.getClass() == Ref3DPtg.class){            externSheetIndex =  ((Ref3DPtg) oldPtg).getExternSheetIndex();        }        if (ra.hasRange()) {        	// Is it contiguous or not?        	AreaReference[] refs =         		AreaReference.generateContiguous(ref);            this.setDefinitionTextLength((short)0);            // Add the area reference(s)         	for(int i=0; i<refs.length; i++) {	            ptg = new Area3DPtg();	            ((Area3DPtg) ptg).setExternSheetIndex(externSheetIndex);	            ((Area3DPtg) ptg).setArea(refs[i].toString());	            field_13_name_definition.push(ptg);	            this.setDefinitionTextLength( (short)(getDefinitionLength() + ptg.getSize()) );        	}        	// And then a union if we had more than one area        	if(refs.length > 1) {        		ptg = new UnionPtg();                field_13_name_definition.push(ptg);	            this.setDefinitionTextLength( (short)(getDefinitionLength() + ptg.getSize()) );        	}        } else {            ptg = new Ref3DPtg();            ((Ref3DPtg) ptg).setExternSheetIndex(externSheetIndex);            ((Ref3DPtg) ptg).setArea(ref);            field_13_name_definition.push(ptg);            this.setDefinitionTextLength((short)ptg.getSize());        }    }    /**     * called by the constructor, should set class level fields.  Should throw     * runtime exception for bad/icomplete data.     *     * @param in the RecordInputstream to read the record from     */    protected void fillFields(RecordInputStream in) {        field_1_option_flag             = in.readShort();        field_2_keyboard_shortcut       = in.readByte();        field_3_length_name_text        = in.readByte();        field_4_length_name_definition  = in.readShort();        field_5_index_to_sheet          = in.readShort();        field_6_equals_to_index_to_sheet= in.readShort();        field_7_length_custom_menu      = in.readByte();        field_8_length_description_text = in.readByte();        field_9_length_help_topic_text  = in.readByte();        field_10_length_status_bar_text = in.readByte();                    //store the name in byte form if it's a builtin name        field_11_compressed_unicode_flag= in.readByte();                if (this.isBuiltInName()) {           field_12_builtIn_name = in.readByte();        } else {                           if (field_11_compressed_unicode_flag == 1) {             field_12_name_text = in.readUnicodeLEString(field_3_length_name_text);           } else {             field_12_name_text = in.readCompressedUnicode(field_3_length_name_text);           }        }                    field_13_name_definition = Ptg.createParsedExpressionTokens(field_4_length_name_definition, in);            //Who says that this can only ever be compressed unicode???        field_14_custom_menu_text       = in.readCompressedUnicode(LittleEndian.ubyteToInt(field_7_length_custom_menu));            field_15_description_text       = in.readCompressedUnicode(LittleEndian.ubyteToInt(field_8_length_description_text));            field_16_help_topic_text        = in.readCompressedUnicode(LittleEndian.ubyteToInt(field_9_length_help_topic_text));            field_17_status_bar_text        = in.readCompressedUnicode(LittleEndian.ubyteToInt(field_10_length_status_bar_text));        /*} */    }    /**     * return the non static version of the id for this record.     */    public short getSid() {        return sid;    }    /*      20 00       00       01       1A 00 // sz = 0x1A = 26      00 00       01 00       00       00       00       00       00 // unicode flag      07 // name            29 17 00 3B 00 00 00 00 FF FF 00 00 02 00 3B 00 //{ 26      00 07 00 07 00 00 00 FF 00 10                   //  }                        20 00       00       01       0B 00 // sz = 0xB = 11      00 00       01 00       00       00       00       00       00 // unicode flag      07 // name            3B 00 00 07 00 07 00 00 00 FF 00   // { 11 }  */    /*      18, 00,       1B, 00,             20, 00,       00,       01,       0B, 00,       00,       00,       00,       00,       00,       07,       3B 00 00 07 00 07 00 00 00 FF 00 ]          */    /**     * @see Object#toString()     */    public String toString() {        StringBuffer buffer = new StringBuffer();        buffer.append("[NAME]\n");        buffer.append("    .option flags         = ").append( HexDump.toHex( field_1_option_flag ) )            .append("\n");        buffer.append("    .keyboard shortcut    = ").append( HexDump.toHex( field_2_keyboard_shortcut ) )            .append("\n");        buffer.append("    .length of the name   = ").append( field_3_length_name_text )            .append("\n");        buffer.append("    .size of the formula data = ").append( field_4_length_name_definition )            .append("\n");        buffer.append("    .unused                   = ").append( field_5_index_to_sheet )            .append("\n");        buffer.append("    .index to sheet (1-based, 0=Global)           = ").append( field_6_equals_to_index_to_sheet )            .append("\n");        buffer.append("    .Length of menu text (character count)        = ").append( field_7_length_custom_menu )            .append("\n");        buffer.append("    .Length of description text (character count) = ").append( field_8_length_description_text )            .append("\n");        buffer.append("    .Length of help topic text (character count)  = ").append( field_9_length_help_topic_text )            .append("\n");        buffer.append("    .Length of status bar text (character count)  = ").append( field_10_length_status_bar_text )            .append("\n");        buffer.append("    .Name (Unicode flag)  = ").append( field_11_compressed_unicode_flag )            .append("\n");        buffer.append("    .Name (Unicode text)  = ").append( getNameText() )            .append("\n");                buffer.append("    .Parts (" + field_13_name_definition.size() +"):")            .append("\n");        Iterator it = field_13_name_definition.iterator();        while(it.hasNext()) {        	Ptg ptg = (Ptg)it.next();        	buffer.append("       " + ptg.toString()).append("\n");        }                buffer.append("    .Menu text (Unicode string without length field)        = ").append( field_14_custom_menu_text )            .append("\n");        buffer.append("    .Description text (Unicode string without length field) = ").append( field_15_description_text )            .append("\n");        buffer.append("    .Help topic text (Unicode string without length field)  = ").append( field_16_help_topic_text )            .append("\n");        buffer.append("    .Status bar text (Unicode string without length field)  = ").append( field_17_status_bar_text )            .append("\n");        buffer.append("[/NAME]\n");                return buffer.toString();    }	/**Creates a human readable name for built in types	 * @return Unknown if the built-in name cannot be translated	 */	protected String translateBuiltInName(byte name)	{	    switch (name)	    {	        case NameRecord.BUILTIN_AUTO_ACTIVATE :     return "Auto_Activate";	        case NameRecord.BUILTIN_AUTO_CLOSE :        return "Auto_Close";	        case NameRecord.BUILTIN_AUTO_DEACTIVATE :   return "Auto_Deactivate";	        case NameRecord.BUILTIN_AUTO_OPEN :         return "Auto_Open";	        case NameRecord.BUILTIN_CONSOLIDATE_AREA :  return "Consolidate_Area";	        case NameRecord.BUILTIN_CRITERIA :          return "Criteria";	        case NameRecord.BUILTIN_DATABASE :          return "Database";	        case NameRecord.BUILTIN_DATA_FORM :         return "Data_Form";            	        case NameRecord.BUILTIN_PRINT_AREA :        return "Print_Area";	        case NameRecord.BUILTIN_PRINT_TITLE :       return "Print_Titles";	        case NameRecord.BUILTIN_RECORDER :          return "Recorder";	        case NameRecord.BUILTIN_SHEET_TITLE :       return "Sheet_Title";	        	    }	    	    return "Unknown";	}}

⌨️ 快捷键说明

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