📄 headerfooter.java
字号:
* determine if fontName is a valid font.
*
* @param fontName name of the font to use
*/
protected void setFontName(String fontName)
{
// Font name must be in quotations
appendInternal("&\"");
appendInternal(fontName);
appendInternal('\"');
}
/**
* Sets the font size of text subsequently appended to this
* object. Previously appended text is not affected.
* <p/>
* Valid point sizes are between 1 and 99 (inclusive). If
* size is outside this range, this method returns false
* and does not change font size. If size is within this
* range, the font size is changed and true is returned.
*
* @param size The size in points. Valid point sizes are
* between 1 and 99 (inclusive).
* @return true if the font size was changed, false if font
* size was not changed because 1 > size > 99.
*/
protected boolean setFontSize(int size)
{
if (size < 1 || size > 99)
{
return false;
}
// A two digit number should be used -- even if the
// leading number is just a zero.
String fontSize;
if (size < 10)
{
// single-digit -- make two digit
fontSize = "0" + size;
}
else
{
fontSize = Integer.toString(size);
}
appendInternal('&');
appendInternal(fontSize);
return true;
}
/**
* Appends the page number
*/
protected void appendPageNumber()
{
appendInternal(PAGENUM);
}
/**
* Appends the total number of pages
*/
protected void appendTotalPages()
{
appendInternal(TOTAL_PAGENUM);
}
/**
* Appends the current date
*/
protected void appendDate()
{
appendInternal(DATE);
}
/**
* Appends the current time
*/
protected void appendTime()
{
appendInternal(TIME);
}
/**
* Appends the workbook name
*/
protected void appendWorkbookName()
{
appendInternal(WORKBOOK_NAME);
}
/**
* Appends the worksheet name
*/
protected void appendWorkSheetName()
{
appendInternal(WORKSHEET_NAME);
}
/**
* Clears the contents of this portion
*/
protected void clear()
{
contents = null;
}
/**
* Queries if the contents are empty
*
* @return TRUE if the contents are empty, FALSE otherwise
*/
protected boolean empty()
{
if (contents == null || contents.length() == 0)
{
return true;
}
else
{
return false;
}
}
}
/**
* The left aligned header/footer contents
*/
private Contents left;
/**
* The right aligned header/footer contents
*/
private Contents right;
/**
* The centrally aligned header/footer contents
*/
private Contents centre;
/**
* Default constructor.
*/
protected HeaderFooter()
{
left = createContents();
right = createContents();
centre = createContents();
}
/**
* Copy constructor
*
* @param c the item to copy
*/
protected HeaderFooter(HeaderFooter hf)
{
left = createContents(hf.left);
right = createContents(hf.right);
centre = createContents(hf.centre);
}
/**
* Constructor used when reading workbooks to separate the left, right
* a central part of the strings into their constituent parts
*/
protected HeaderFooter(String s)
{
if (s == null || s.length() == 0)
{
left = createContents();
right = createContents();
centre = createContents();
return;
}
int pos = 0;
int leftPos = s.indexOf(LEFT_ALIGN);
int rightPos = s.indexOf(RIGHT_ALIGN);
int centrePos = s.indexOf(CENTRE);
// Do the left position string
if (pos == leftPos)
{
if (centrePos != -1)
{
left = createContents(s.substring(pos + 2, centrePos));
pos = centrePos;
}
else if (rightPos != -1 )
{
left = createContents(s.substring(pos + 2, rightPos));
pos = rightPos;
}
else
{
left = createContents(s.substring(pos + 2));
pos = s.length();
}
}
// Do the centrally positioned part of the string. This is the default
// if no alignment string is specified
if (pos == centrePos ||
(leftPos == -1 && rightPos == -1 && centrePos == -1))
{
if (rightPos != -1)
{
centre = createContents(s.substring(pos + 2, rightPos));
pos = rightPos;
}
else
{
centre = createContents(s.substring(pos + 2));
pos = s.length();
}
}
// Do the right positioned part of the string
if (pos == rightPos)
{
right = createContents(s.substring(pos + 2));
pos = s.length();
}
if (left == null)
{
left = createContents();
}
if (centre == null)
{
centre = createContents();
}
if (right == null)
{
right = createContents();
}
}
/**
* Retrieves a <code>String</code>ified
* version of this object
*
* @return the header string
*/
public String toString()
{
StringBuffer hf = new StringBuffer();
if (!left.empty())
{
hf.append(LEFT_ALIGN);
hf.append(left.getContents());
}
if (!centre.empty())
{
hf.append(CENTRE);
hf.append(centre.getContents());
}
if (!right.empty())
{
hf.append(RIGHT_ALIGN);
hf.append(right.getContents());
}
return hf.toString();
}
/**
* Accessor for the contents which appear on the right hand side of the page
*
* @return the right aligned contents
*/
protected Contents getRightText()
{
return right;
}
/**
* Accessor for the contents which in the centre of the page
*
* @return the centrally aligned contents
*/
protected Contents getCentreText()
{
return centre;
}
/**
* Accessor for the contents which appear on the left hand side of the page
*
* @return the left aligned contents
*/
protected Contents getLeftText()
{
return left;
}
/**
* Clears the contents of the header/footer
*/
protected void clear()
{
left.clear();
right.clear();
centre.clear();
}
/**
* Creates internal class of the appropriate type
*/
protected abstract Contents createContents();
/**
* Creates internal class of the appropriate type
*/
protected abstract Contents createContents(String s);
/**
* Creates internal class of the appropriate type
*/
protected abstract Contents createContents(Contents c);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -