📄 rtflist.java
字号:
} } } /** * Writes the definition part of this list level * @param result * @throws IOException * @since 2.1.3 */ public void writeDefinition(final OutputStream result) throws IOException { result.write(OPEN_GROUP); result.write(LIST); result.write(LIST_TEMPLATE_ID); result.write(intToByteArray(document.getRandomInt())); int levelsToWrite = -1; switch(this.listType) { case LIST_TYPE_NORMAL: levelsToWrite = listLevels.size(); break; case LIST_TYPE_SIMPLE: result.write(LIST_SIMPLE); result.write(intToByteArray(1)); levelsToWrite = 1; break; case LIST_TYPE_HYBRID: result.write(LIST_HYBRID); levelsToWrite = listLevels.size(); break; default: break; } this.document.outputDebugLinebreak(result); // TODO: Figure out hybrid because multi-level hybrid does not work. // Seems hybrid is mixed type all single level - Simple = single level // SIMPLE1/HYRBID // 1. Line 1 // 2. Line 2 // MULTI-LEVEL LISTS Are Simple0 - 9 levels (0-8) all single digit // 1. Line 1 // 1.1. Line 1.1 // 1.2. Line 1.2 // 2. Line 2 // write the listlevels here for(int i = 0; i<levelsToWrite; i++) { ((RtfListLevel)listLevels.get(i)).writeDefinition(result); this.document.outputDebugLinebreak(result); } result.write(LIST_ID); result.write(intToByteArray(this.listID)); result.write(CLOSE_GROUP); this.document.outputDebugLinebreak(result); if(items != null) { for(int i = 0; i < items.size(); i++) { RtfElement rtfElement = (RtfElement) items.get(i); if(rtfElement instanceof RtfList) { RtfList rl = (RtfList)rtfElement; rl.writeDefinition(result); break; } else if(rtfElement instanceof RtfListItem) { RtfListItem rli = (RtfListItem) rtfElement; if(rli.writeDefinition(result)) break; } } } } /** * Writes the content of the RtfList * @since 2.1.3 */ public void writeContent(final OutputStream result) throws IOException { if(!this.inTable) { result.write(OPEN_GROUP); } int itemNr = 0; if(items != null) { for(int i = 0; i < items.size(); i++) { RtfElement thisRtfElement = (RtfElement) items.get(i); //thisRtfElement.writeContent(result); if(thisRtfElement instanceof RtfListItem) { itemNr++; RtfListItem rtfElement = (RtfListItem)thisRtfElement; RtfListLevel listLevel = rtfElement.getParent(); if(listLevel.getListLevel() == 0) { correctIndentation(); } if(i == 0) { listLevel.writeListBeginning(result); writeListNumbers(result); } writeListTextBlock(result, itemNr, listLevel); rtfElement.writeContent(result); if(i < (items.size() - 1) || !this.inTable || listLevel.getListType() > 0) { // TODO Fix no paragraph on last list item in tables result.write(RtfParagraph.PARAGRAPH); } this.document.outputDebugLinebreak(result); } else if(thisRtfElement instanceof RtfList) { ((RtfList)thisRtfElement).writeContent(result);// ((RtfList)thisRtfElement).writeListBeginning(result); writeListNumbers(result); this.document.outputDebugLinebreak(result); } } } if(!this.inTable) { result.write(CLOSE_GROUP); result.write(RtfParagraph.PARAGRAPH_DEFAULTS); } } /** * * @param result * @param itemNr * @param listLevel * @throws IOException * @since 2.1.3 */ protected void writeListTextBlock(final OutputStream result, int itemNr, RtfListLevel listLevel) throws IOException { result.write(OPEN_GROUP); result.write(RtfList.LIST_TEXT); result.write(RtfParagraph.PARAGRAPH_DEFAULTS); if(this.inTable) { result.write(RtfParagraph.IN_TABLE); } result.write(RtfFontList.FONT_NUMBER); if(listLevel.getListType() != RtfListLevel.LIST_TYPE_BULLET) { result.write(intToByteArray(listLevel.getFontNumber().getFontNumber())); } else { result.write(intToByteArray(listLevel.getFontBullet().getFontNumber())); } listLevel.writeIndentation(result); result.write(DELIMITER); if(listLevel.getListType() != RtfListLevel.LIST_TYPE_BULLET) { switch(listLevel.getListType()) { case RtfListLevel.LIST_TYPE_NUMBERED : result.write(intToByteArray(itemNr)); break; case RtfListLevel.LIST_TYPE_UPPER_LETTERS : result.write(DocWriter.getISOBytes(RomanAlphabetFactory.getUpperCaseString(itemNr))); break; case RtfListLevel.LIST_TYPE_LOWER_LETTERS : result.write(DocWriter.getISOBytes(RomanAlphabetFactory.getLowerCaseString(itemNr))); break; case RtfListLevel.LIST_TYPE_UPPER_ROMAN : result.write(DocWriter.getISOBytes(RomanNumberFactory.getUpperCaseString(itemNr))); break; case RtfListLevel.LIST_TYPE_LOWER_ROMAN : result.write(DocWriter.getISOBytes(RomanNumberFactory.getLowerCaseString(itemNr))); break; } result.write(LIST_NUMBER_END); } else { this.document.filterSpecialChar(result, listLevel.getBulletCharacter(), true, false); } result.write(TAB); result.write(CLOSE_GROUP); } /** * Writes only the list number and list level number. * * @param result The <code>OutputStream</code> to write to * @throws IOException On i/o errors. * @since 2.1.3 */ protected void writeListNumbers(final OutputStream result) throws IOException { result.write(RtfList.LIST_NUMBER); result.write(intToByteArray(listNumber)); } /** * Create a default set of listlevels * @since 2.1.3 */ protected void createDefaultLevels() { this.listLevels = new ArrayList(); // listlevels for(int i=0; i<=8; i++) { // create a list level RtfListLevel ll = new RtfListLevel(this.document); ll.setListType(RtfListLevel.LIST_TYPE_NUMBERED); ll.setFirstIndent(0); ll.setLeftIndent(0); ll.setLevelTextNumber(i); ll.setTentative(true); ll.correctIndentation(); this.listLevels.add(ll); } } /** * Gets the id of this list * * @return Returns the list number. * @since 2.1.3 */ public int getListNumber() { return listNumber; } /** * Sets the id of this list * * @param listNumber The list number to set. * @since 2.1.3 */ public void setListNumber(int listNumber) { this.listNumber = listNumber; } /** * Sets whether this RtfList is in a table. Sets the correct inTable setting for all * child elements. * * @param inTable <code>True</code> if this RtfList is in a table, <code>false</code> otherwise * @since 2.1.3 */ public void setInTable(boolean inTable) { super.setInTable(inTable); for(int i = 0; i < this.items.size(); i++) { ((RtfBasicElement) this.items.get(i)).setInTable(inTable); } } /** * Sets whether this RtfList is in a header. Sets the correct inTable setting for all * child elements. * * @param inHeader <code>True</code> if this RtfList is in a header, <code>false</code> otherwise * @since 2.1.3 */ public void setInHeader(boolean inHeader) { super.setInHeader(inHeader); for(int i = 0; i < this.items.size(); i++) { ((RtfBasicElement) this.items.get(i)).setInHeader(inHeader); } } /** * Correct the indentation of this RtfList by adding left/first line indentation * from the parent RtfList. Also calls correctIndentation on all child RtfLists. * @since 2.1.3 */ protected void correctIndentation() { // TODO: Fix// if(this.parentList != null) {// this.leftIndent = this.leftIndent + this.parentList.getLeftIndent() + this.parentList.getFirstIndent();// } for(int i = 0; i < this.items.size(); i++) { if(this.items.get(i) instanceof RtfList) { ((RtfList) this.items.get(i)).correctIndentation(); } else if(this.items.get(i) instanceof RtfListItem) { ((RtfListItem) this.items.get(i)).correctIndentation(); } } } /** * Set the list ID number * @param id * @since 2.1.3 */ public void setID(int id) { this.listID = id; } /** * Get the list ID number * @return this list id * @since 2.1.3 */ public int getID() { return this.listID; } /** * @return the listType * @see RtfList#LIST_TYPE_NORMAL * @see RtfList#LIST_TYPE_SIMPLE * @see RtfList#LIST_TYPE_HYBRID * @since 2.1.3 */ public int getListType() { return listType; } /** * @param listType the listType to set * @see RtfList#LIST_TYPE_NORMAL * @see RtfList#LIST_TYPE_SIMPLE * @see RtfList#LIST_TYPE_HYBRID * @since 2.1.3 */ public void setListType(int listType) throws InvalidParameterException { if(listType == LIST_TYPE_NORMAL || listType == LIST_TYPE_SIMPLE || listType == LIST_TYPE_HYBRID ) { this.listType = listType; } else { throw new InvalidParameterException("Invalid listType value."); } } /** * @return the parentList * @since 2.1.3 */ public RtfList getParentList() { return parentList; } /** * @param parentList the parentList to set * @since 2.1.3 */ public void setParentList(RtfList parentList) { this.parentList = parentList; } /** * @return the name * @since 2.1.3 */ public String getName() { return name; } /** * @param name the name to set * @since 2.1.3 */ public void setName(String name) { this.name = name; } /** * @return the list at the index * @since 2.1.3 */ public RtfListLevel getListLevel(int index) { if(listLevels != null) { return (RtfListLevel)this.listLevels.get(index); } else return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -