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

📄 rectangle.java

📁 iText是一个能够快速产生PDF文件的java类库。iText的java类对于那些要产生包含文本
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

	public void setBorderColor(Color value) {
		borderColor = value;
	}

	// backgroundcolor

	/**
	 * Gets the backgroundcolor.
	 * 
	 * @return a value
	 */
	public Color getBackgroundColor() {
		return backgroundColor;
	}
	
	/**
	 * Sets the backgroundcolor of the rectangle.
	 * 
	 * @param value
	 *            the new value
	 */

	public void setBackgroundColor(Color value) {
		backgroundColor = value;
	}

	/**
	 * Gets the grayscale.
	 * 
	 * @return a value
	 */

	public float getGrayFill() {
        if (backgroundColor instanceof GrayColor)
            return ((GrayColor)backgroundColor).getGray();
        else
            return 0;
	}

	/**
	 * Sets the grayscale of the rectangle.
	 * 
	 * @param value
	 *            the new value
	 */
	public void setGrayFill(float value) {
        backgroundColor = new GrayColor(value);
	}

	// variable borders
	
	/**
	 * Indicates whether variable width borders are being used. Returns true if
	 * <CODE>setBorderWidthLeft, setBorderWidthRight, setBorderWidthTop, or
	 * setBorderWidthBottom</CODE> has been called.
	 * 
	 * @return true if variable width borders are in use
	 *  
	 */
	public boolean isUseVariableBorders() {
		return useVariableBorders;
	}

	/**
	 * Sets a parameter indicating if the rectangle has variable borders
	 * 
	 * @param useVariableBorders
	 *            indication if the rectangle has variable borders
	 */
	public void setUseVariableBorders(boolean useVariableBorders) {
		this.useVariableBorders = useVariableBorders;
	}
	
	// variable border width

	/** Gives the border width of a specific side. */
	private float getVariableBorderWidth(float variableWidthValue, int side) {
		if ((border & side) != 0) {
			return variableWidthValue != UNDEFINED ? variableWidthValue
					: borderWidth;
		} else {
			return 0;
		}
	}

	/**
	 * Updates the border flag for a side based on the specified width. A width
	 * of 0 will disable the border on that side. Any other width enables it.
	 * 
	 * @param width
	 *            width of border
	 * @param side
	 *            border side constant
	 */
	private void updateBorderBasedOnWidth(float width, int side) {
		useVariableBorders = true;
		if (width > 0) {
			enableBorderSide(side);
		} else {
			disableBorderSide(side);
		}
	}

	/**
	 * Gets the width of a border.
	 * 
	 * @return a width
	 */
	public float getBorderWidthLeft() {
		return getVariableBorderWidth(borderWidthLeft, LEFT);
	}

	/**
	 * Sets the width of a border
	 * 
	 * @param borderWidthLeft
	 *            a width
	 */
	public void setBorderWidthLeft(float borderWidthLeft) {
		this.borderWidthLeft = borderWidthLeft;
		updateBorderBasedOnWidth(borderWidthLeft, LEFT);
	}

	/**
	 * Gets the width of a border.
	 * 
	 * @return a width
	 */
	public float getBorderWidthRight() {
		return getVariableBorderWidth(borderWidthRight, RIGHT);
	}

	/**
	 * Sets the width of a border
	 * 
	 * @param borderWidthRight
	 *            a width
	 */
	public void setBorderWidthRight(float borderWidthRight) {
		this.borderWidthRight = borderWidthRight;
		updateBorderBasedOnWidth(borderWidthRight, RIGHT);
	}

	/**
	 * Gets the width of a border.
	 * 
	 * @return a width
	 */
	public float getBorderWidthTop() {
		return getVariableBorderWidth(borderWidthTop, TOP);
	}

	/**
	 * Sets the width of a border
	 * 
	 * @param borderWidthTop
	 *            a width
	 */
	public void setBorderWidthTop(float borderWidthTop) {
		this.borderWidthTop = borderWidthTop;
		updateBorderBasedOnWidth(borderWidthTop, TOP);
	}

	/**
	 * Gets the width of a border.
	 * 
	 * @return a width
	 */
	public float getBorderWidthBottom() {
		return getVariableBorderWidth(borderWidthBottom, BOTTOM);
	}

	/**
	 * Sets the width of a border
	 * 
	 * @param borderWidthBottom
	 *            a width
	 */
	public void setBorderWidthBottom(float borderWidthBottom) {
		this.borderWidthBottom = borderWidthBottom;
		updateBorderBasedOnWidth(borderWidthBottom, BOTTOM);
	}

	// variable border color
	
	/**
	 * Gets the color of a border.
	 * 
	 * @return a color value
	 */
	public Color getBorderColorLeft() {
		if (borderColorLeft == null) return borderColor;
		return borderColorLeft;
	}

	/**
	 * Sets the value of the border color
	 * 
	 * @param value
	 *            a color value
	 */
	public void setBorderColorLeft(Color value) {
		borderColorLeft = value;
	}

	/**
	 * Gets the color of a border.
	 * 
	 * @return a color value
	 */
	public Color getBorderColorRight() {
		if (borderColorRight == null) return borderColor;
		return borderColorRight;
	}

	/**
	 * Sets the value of the border color
	 * 
	 * @param value
	 *            a color value
	 */
	public void setBorderColorRight(Color value) {
		borderColorRight = value;
	}

	/**
	 * Gets the color of a border.
	 * 
	 * @return a color value
	 */
	public Color getBorderColorTop() {
		if (borderColorTop == null) return borderColor;
		return borderColorTop;
	}

	/**
	 * Sets the value of the border color
	 * 
	 * @param value
	 *            a color value
	 */
	public void setBorderColorTop(Color value) {
		borderColorTop = value;
	}

	/**
	 * Gets the color of a border.
	 * 
	 * @return a color value
	 */
	public Color getBorderColorBottom() {
		if (borderColorBottom == null) return borderColor;
		return borderColorBottom;
	}

	/**
	 * Sets the value of the border color
	 * 
	 * @param value
	 *            a color value
	 */
	public void setBorderColorBottom(Color value) {
		borderColorBottom = value;
	}

	// special methods

	/**
	 * Gets a Rectangle that is altered to fit on the page.
	 * 
	 * @param top
	 *            the top position
	 * @param bottom
	 *            the bottom position
	 * @return a <CODE>Rectangle</CODE>
	 */
	public Rectangle rectangle(float top, float bottom) {
		Rectangle tmp = new Rectangle(this);
		if (getTop() > top) {
			tmp.setTop(top);
			tmp.disableBorderSide(TOP);
		}
		if (getBottom() < bottom) {
			tmp.setBottom(bottom);
			tmp.disableBorderSide(BOTTOM);
		}
		return tmp;
	}

	/**
	 * Copies all of the parameters from a <CODE>Rectangle</CODE> object
	 * except the position.
	 * 
	 * @param rect
	 *            <CODE>Rectangle</CODE> to copy from
	 */
	public void cloneNonPositionParameters(Rectangle rect) {
		this.rotation = rect.rotation;
		this.border = rect.border;
		this.borderWidth = rect.borderWidth;
		this.borderColor = rect.borderColor;
		this.backgroundColor = rect.backgroundColor;
		this.useVariableBorders = rect.useVariableBorders;
		this.borderWidthLeft = rect.borderWidthLeft;
		this.borderWidthRight = rect.borderWidthRight;
		this.borderWidthTop = rect.borderWidthTop;
		this.borderWidthBottom = rect.borderWidthBottom;
		this.borderColorLeft = rect.borderColorLeft;
		this.borderColorRight = rect.borderColorRight;
		this.borderColorTop = rect.borderColorTop;
		this.borderColorBottom = rect.borderColorBottom;
	}

	/**
	 * Copies all of the parameters from a <CODE>Rectangle</CODE> object
	 * except the position.
	 * 
	 * @param rect
	 *            <CODE>Rectangle</CODE> to copy from
	 */
	public void softCloneNonPositionParameters(Rectangle rect) {
		if (rect.rotation != 0)
			this.rotation = rect.rotation;
		if (rect.border != UNDEFINED)
			this.border = rect.border;
		if (rect.borderWidth != UNDEFINED)
			this.borderWidth = rect.borderWidth;
		if (rect.borderColor != null)
			this.borderColor = rect.borderColor;
		if (rect.backgroundColor != null)
			this.backgroundColor = rect.backgroundColor;
		if (useVariableBorders)
			this.useVariableBorders = rect.useVariableBorders;
		if (rect.borderWidthLeft != UNDEFINED)
			this.borderWidthLeft = rect.borderWidthLeft;
		if (rect.borderWidthRight != UNDEFINED)
			this.borderWidthRight = rect.borderWidthRight;
		if (rect.borderWidthTop != UNDEFINED)
			this.borderWidthTop = rect.borderWidthTop;
		if (rect.borderWidthBottom != UNDEFINED)
			this.borderWidthBottom = rect.borderWidthBottom;
		if (rect.borderColorLeft != null)
			this.borderColorLeft = rect.borderColorLeft;
		if (rect.borderColorRight != null)
			this.borderColorRight = rect.borderColorRight;
		if (rect.borderColorTop != null)
			this.borderColorTop = rect.borderColorTop;
		if (rect.borderColorBottom != null)
			this.borderColorBottom = rect.borderColorBottom;
	}
	
	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		StringBuffer buf = new StringBuffer("Rectangle: ");
		buf.append(getWidth());
		buf.append('x');
		buf.append(getHeight());
		buf.append(" (rot: ");
		buf.append(rotation);
		buf.append(" degrees)");
		return buf.toString();
	}

// deprecated stuff

	/**
	 * Returns the lower left x-coordinate.
	 * 
	 * @return the lower left x-coordinate
	 * @deprecated Use {@link #getLeft()} instead
	 */
	public float left() {
		return getLeft();
	}

	/**
	 * Returns the upper right x-coordinate.
	 * 
	 * @return the upper right x-coordinate
	 * @deprecated Use {@link #getRight()} instead
	 */
	public float right() {
		return getRight();
	}

	/**
	 * Returns the upper right y-coordinate.
	 * 
	 * @return the upper right y-coordinate
	 * @deprecated Use {@link #getTop()} instead
	 */
	public float top() {
		return getTop();
	}

	/**
	 * Returns the lower left y-coordinate.
	 * 
	 * @return the lower left y-coordinate
	 * @deprecated Use {@link #getBottom()} instead
	 */
	public float bottom() {
		return getBottom();
	}

	/**
	 * Returns the lower left x-coordinate, considering a given margin.
	 * 
	 * @param margin
	 *            a margin
	 * @return the lower left x-coordinate
	 * @deprecated Use {@link #getLeft(float)} instead
	 */
	public float left(float margin) {
		return getLeft(margin);
	}

	/**
	 * Returns the upper right x-coordinate, considering a given margin.
	 * 
	 * @param margin
	 *            a margin
	 * @return the upper right x-coordinate
	 * @deprecated Use {@link #getRight(float)} instead
	 */
	public float right(float margin) {
		return getRight(margin);
	}

	/**
	 * Returns the width of the rectangle.
	 * 
	 * @return a width
	 * @deprecated Use {@link #getWidth()} instead
	 */
	public float width() {
		return getWidth();
	}

	/**
	 * Returns the upper right y-coordinate, considering a given margin.
	 * 
	 * @param margin
	 *            a margin
	 * @return the upper right y-coordinate
	 * @deprecated Use {@link #getTop(float)} instead
	 */
	public float top(float margin) {
		return getTop(margin);
	}

	/**
	 * Returns the lower left y-coordinate, considering a given margin.
	 * 
	 * @param margin
	 *            a margin
	 * @return the lower left y-coordinate
	 * @deprecated Use {@link #getBottom(float)} instead
	 */
	public float bottom(float margin) {
		return getBottom(margin);
	}

	/**
	 * Returns the height of the rectangle.
	 * 
	 * @return a height
	 * @deprecated Use {@link #getHeight()} instead
	 */
	public float height() {
		return getHeight();
	}

	/**
	 * Returns the exact type of the border.
	 * 
	 * @return a value
	 * @deprecated Use {@link #getBorder()} instead
	 */
	public int border() {
		return getBorder();
	}

	/**
	 * Gets the borderwidth.
	 * 
	 * @return a value
	 * @deprecated Use {@link #getBorderWidth()} instead
	 */
	public float borderWidth() {
		return getBorderWidth();
	}

	/**
	 * Gets the color of the border.
	 * 
	 * @return a value
	 * @deprecated Use {@link #getBorderColor()} instead
	 */
	
	public Color borderColor() {
		return getBorderColor();
	}

	/**
	 * Gets the backgroundcolor.
	 * 
	 * @return a value
	 * @deprecated Use {@link #getBackgroundColor()} instead
	 */
	public Color backgroundColor() {
		return getBackgroundColor();
	}

	/**
	 * Gets the grayscale.
	 * 
	 * @return a value
	 * @deprecated Use {@link #getGrayFill()} instead
	 */
	
	public float grayFill() {
		return getGrayFill();
	}
	
}

⌨️ 快捷键说明

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