📄 section.java
字号:
add(section); return section; } /** * Creates a <CODE>Section</CODE>, add it to this <CODE>Section</CODE> and returns it. * * @param title the title of the new section * @param numberDepth the numberDepth of the section */ public Section addSection(Paragraph title, int numberDepth) { Section section = new Section(title, numberDepth); add(section); return section; } /** * Creates a <CODE>Section</CODE>, adds it to this <CODE>Section</CODE> and returns it. * * @param title the title of the new section */ public Section addSection(Paragraph title) { Section section = new Section(title, 1); add(section); return section; } /** * Adds a <CODE>Section</CODE> to this <CODE>Section</CODE> and returns it. * * @param indentation the indentation of the new section * @param title the title of the new section * @param numberDepth the numberDepth of the section */ public Section addSection(float indentation, String title, int numberDepth) { Section section = new Section(new Paragraph(title), numberDepth); section.setIndentation(indentation); add(section); return section; } /** * Adds a <CODE>Section</CODE> to this <CODE>Section</CODE> and returns it. * * @param title the title of the new section * @param numberDepth the numberDepth of the section */ public Section addSection(String title, int numberDepth) { Section section = new Section(new Paragraph(title), numberDepth); add(section); return section; } /** * Adds a <CODE>Section</CODE> to this <CODE>Section</CODE> and returns it. * * @param indentation the indentation of the new section * @param title the title of the new section */ public Section addSection(float indentation, String title) { Section section = new Section(new Paragraph(title), 1); section.setIndentation(indentation); add(section); return section; } /** * Adds a <CODE>Section</CODE> to this <CODE>Section</CODE> and returns it. * * @param title the title of the new section */ public Section addSection(String title) { Section section = new Section(new Paragraph(title), 1); add(section); return section; } /** * Creates a given <CODE>Section</CODE> following a set of attributes and adds it to this one. * * @param attributes the attributes * @return a Section */ public Section addSection(Properties attributes) { Section section = new Section(new Paragraph(""), 1); String value; if ((value = (String)attributes.remove(ElementTags.NUMBER)) != null) { subsections = Integer.parseInt(value) - 1; } section.set(attributes); add(section); return section; } // public methods /** * Alters the attributes of this <CODE>Section</CODE>. * * @param attributes the attributes */ public void set(Properties attributes) { String value; if ((value = (String)attributes.remove(ElementTags.NUMBERDEPTH)) != null) { setNumberDepth(Integer.parseInt(value)); } if ((value = (String)attributes.remove(ElementTags.INDENT)) != null) { setIndentation(Float.valueOf(value + "f").floatValue()); } if ((value = (String)attributes.remove(ElementTags.INDENTATIONLEFT)) != null) { setIndentationLeft(Float.valueOf(value + "f").floatValue()); } if ((value = (String)attributes.remove(ElementTags.INDENTATIONRIGHT)) != null) { setIndentationRight(Float.valueOf(value + "f").floatValue()); } } /** * Sets the title of this section. * * @param title the new title */ public void setTitle(Paragraph title) { this.title = title; } /** * Sets the depth of the sectionnumbers that will be shown preceding the title. * <P> * If the numberdepth is 0, the sections will not be numbered. If the numberdepth * is 1, the section will be numbered with their own number. If the numberdepth is * higher (for instance x > 1), the numbers of x - 1 parents will be shown. * * @param numberDepth the new numberDepth */ public void setNumberDepth(int numberDepth) { this.numberDepth = numberDepth; } /** * Sets the indentation of this <CODE>Section</CODE> on the left side. * * @param indentation the indentation */ public void setIndentationLeft(float indentation) { indentationLeft = indentation; } /** * Sets the indentation of this <CODE>Section</CODE> on the right side. * * @param indentation the indentation */ public void setIndentationRight(float indentation) { indentationRight = indentation; } /** * Sets the indentation of the content of this <CODE>Section</CODE>. * * @param indentation the indentation */ public void setIndentation(float indentation) { sectionIndent = indentation; } // methods to retrieve information /** * Checks if this object is a <CODE>Chapter</CODE>. * * @return <CODE>true</CODE> if it is a <CODE>Chapter</CODE>, * <CODE>false</CODE> if it is a <CODE>Section</CODE>. */ public boolean isChapter() { return type() == Element.CHAPTER; } /** * Checks if this object is a <CODE>Section</CODE>. * * @return <CODE>true</CODE> if it is a <CODE>Section</CODE>, * <CODE>false</CODE> if it is a <CODE>Chapter</CODE>. */ public boolean isSection() { return type() == Element.SECTION; } /** * Returns the numberdepth of this <CODE>Section</CODE>. * * @return the numberdepth */ public int numberDepth() { return numberDepth; } /** * Returns the indentation of this <CODE>Section</CODE> on the left side. * * @return the indentation */ public float indentationLeft() { return indentationLeft; } /** * Returns the indentation of this <CODE>Section</CODE> on the right side. * * @return the indentation */ public float indentationRight() { return indentationRight; } /** * Returns the indentation of the content of this <CODE>Section</CODE>. * * @return the indentation */ public float indentation() { return sectionIndent; } /** * Returns the depth of this section. * * @return the depth */ public int depth() { return numbers.size(); } /** * Returns the title, preceeded by a certain number of sectionnumbers. * * @return a <CODE>Paragraph</CODE> */ public Paragraph title() { if (title == null) { return null; } int depth = Math.min(numbers.size(), numberDepth); if (depth < 1) { return title; } StringBuffer buf = new StringBuffer(" "); for (int i = 0; i < depth; i++) { buf.insert(0, "."); buf.insert(0, ((Integer) numbers.get(i)).intValue()); } Paragraph result = new Paragraph(title); result.setMarkupAttributes(title.getMarkupAttributes()); result.add(0, new Chunk(buf.toString(), title.font())); return result; } /** * Checks if a given tag corresponds with a title tag for this object. * * @param tag the given tag * @return true if the tag corresponds */ public static boolean isTitle(String tag) { return ElementTags.TITLE.equals(tag); } /** * Checks if a given tag corresponds with this object. * * @param tag the given tag * @return true if the tag corresponds */ public static boolean isTag(String tag) { return ElementTags.SECTION.equals(tag); } /** Getter for property bookmarkOpen. * @return Value of property bookmarkOpen. */ public boolean isBookmarkOpen() { return bookmarkOpen; } /** Setter for property bookmarkOpen. * @param bookmarkOpen false if the bookmark children are not * visible. */ public void setBookmarkOpen(boolean bookmarkOpen) { this.bookmarkOpen = bookmarkOpen; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -