java.lang.Object
java.awt.PageAttributes
- 所有已实现的接口:
-
Cloneable
一组控制打印页面输出的属性。
此类的实例控制使用该实例的每个页面的颜色状态、纸张大小(介质类型)、方向、逻辑原点、打印质量和分辨率。 属性名称尽可能符合Internet打印协议(IPP)1.1。 属性值在可能的情况下部分符合。
要使用接受内部类类型的方法,请传递内部类的常量字段之一的引用。 客户端代码无法创建内部类类型的新实例,因为这些类都没有公共构造函数。 例如,要将颜色状态设置为单色,请使用以下代码:
import java.awt.PageAttributes;
public class MonochromeExample {
public void setMonochrome(PageAttributes pageAttributes) {
pageAttributes.setColor(PageAttributes.ColorType.MONOCHROME);
}
}
每个支持attributeName-默认值的IPP属性都有相应的setattributeNameToDefault方法。 不提供默认值字段。
- 自版本:
- 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class可能颜色状态的类型安全枚举。static final class可能纸张大小的类型安全枚举。static final class可能方向的类型安全枚举。static final class可能原点的类型安全枚举。static final class可能打印质量的类型安全枚举。 -
Constructor Summary
ConstructorsConstructorDescription使用每个属性的默认值构造PageAttributes实例。构造一个与提供的PageAttributes副本相同的PageAttributes实例。PageAttributes(PageAttributes.ColorType color, PageAttributes.MediaType media, PageAttributes.OrientationRequestedType orientationRequested, PageAttributes.OriginType origin, PageAttributes.PrintQualityType printQuality, int[] printerResolution) 使用指定值构造每个属性的PageAttributes实例。 -
Method Summary
Modifier and TypeMethodDescriptionclone()创建并返回此PageAttributes的副本。boolean确定两个PageAttributes是否相等。getColor()返回使用这些属性的页面是否以彩色或单色呈现。getMedia()返回使用这些属性的页面的纸张大小。返回使用这些属性的页面的打印方向。返回使用这些属性的页面在(0, 0)处绘制时是在物理页面的左上角绘制,还是在可打印区域的左上角绘制。int[]返回使用这些属性的页面的打印分辨率。返回使用这些属性的页面的打印质量。inthashCode()返回此PageAttributes的哈希码值。voidset(PageAttributes obj) 将此PageAttributes的所有属性设置为obj的属性的相同值。voidsetColor(PageAttributes.ColorType color) 指定使用这些属性的页面是否以彩色或单色呈现。voidsetMedia(PageAttributes.MediaType media) 指定使用这些属性的页面的期望纸张大小。void将使用这些属性的页面的纸张大小设置为默认区域的默认大小。voidsetOrientationRequested(int orientationRequested) 指定使用这些属性的页面的打印方向。voidsetOrientationRequested(PageAttributes.OrientationRequestedType orientationRequested) 指定使用这些属性的页面的打印方向。void将使用这些属性的页面的打印方向设置为默认。voidsetOrigin(PageAttributes.OriginType origin) 指定使用这些属性的页面在(0, 0)处绘制时是在物理页面的左上角绘制,还是在可打印区域的左上角绘制。voidsetPrinterResolution(int printerResolution) 指定使用这些属性的页面的所需横向和纵向打印分辨率(每英寸点数)。voidsetPrinterResolution(int[] printerResolution) 指定使用这些属性的页面的所需打印分辨率。void将使用这些属性的页面的打印机分辨率设置为默认值。voidsetPrintQuality(int printQuality) 指定使用这些属性的页面的打印质量。voidsetPrintQuality(PageAttributes.PrintQualityType printQuality) 指定使用这些属性的页面的打印质量。void将使用这些属性的页面的打印质量设置为默认值。toString()返回此PageAttributes的字符串表示形式。
-
Constructor Details
-
PageAttributes
public PageAttributes()使用每个属性的默认值构造PageAttributes实例。 -
PageAttributes
构造一个与提供的PageAttributes副本相同的PageAttributes实例。- 参数:
-
obj- 要复制的PageAttributes。
-
PageAttributes
public PageAttributes(PageAttributes.ColorType color, PageAttributes.MediaType media, PageAttributes.OrientationRequestedType orientationRequested, PageAttributes.OriginType origin, PageAttributes.PrintQualityType printQuality, int[] printerResolution) 使用指定值构造每个属性的PageAttributes实例。- 参数:
-
color- ColorType.COLOR或ColorType.MONOCHROME。 -
media- MediaType类的常量字段之一。 -
orientationRequested- OrientationRequestedType.PORTRAIT或OrientationRequestedType.LANDSCAPE。 -
origin- OriginType.PHYSICAL或OriginType.PRINTABLE -
printQuality- PrintQualityType.DRAFT、PrintQualityType.NORMAL或PrintQualityType.HIGH -
printerResolution- 一个包含3个元素的整数数组。 第一个元素必须大于0。 第二个元素必须大于0。 第三个元素必须是3或4。 - 抛出:
-
IllegalArgumentException- 如果违反上述条件中的一个或多个。
-
-
Method Details
-
clone
创建并返回此PageAttributes的副本。 -
set
将此PageAttributes的所有属性设置为obj的属性的相同值。- 参数:
-
obj- 要复制的PageAttributes。
-
getColor
返回使用这些属性的页面是否以彩色或单色呈现。此属性将更新为用户选择的值。- 返回:
- ColorType.COLOR或ColorType.MONOCHROME。
-
setColor
指定使用这些属性的页面是否以彩色或单色呈现。不指定此属性等效于指定ColorType.MONOCHROME。- 参数:
-
color- ColorType.COLOR或ColorType.MONOCHROME。 - 抛出:
-
IllegalArgumentException- 如果颜色为null。
-
getMedia
返回使用这些属性的页面的纸张大小。此属性将更新为用户选择的值。- 返回:
- MediaType类的常量字段之一。
-
setMedia
指定使用这些属性的页面的期望纸张大小。实际纸张大小将由目标打印机的限制确定。如果找不到精确匹配,实现将选择最接近的可能匹配项。不指定此属性等效于指定默认区域的默认大小。美国和加拿大地区的默认大小为MediaType.NA_LETTER。所有其他地区的默认大小为MediaType.ISO_A4。- 参数:
-
media- MediaType类的常量字段之一。 - 抛出:
-
IllegalArgumentException- 如果media为null。
-
setMediaToDefault
public void setMediaToDefault()将使用这些属性的页面的纸张大小设置为默认区域的默认大小。美国和加拿大地区的默认大小为MediaType.NA_LETTER。所有其他地区的默认大小为MediaType.ISO_A4。 -
getOrientationRequested
返回使用这些属性的页面的打印方向。此属性将更新为用户选择的值。- 返回:
- OrientationRequestedType.PORTRAIT或OrientationRequestedType.LANDSCAPE。
-
setOrientationRequested
指定使用这些属性的页面的打印方向。不指定属性等效于指定OrientationRequestedType.PORTRAIT。- 参数:
-
orientationRequested- OrientationRequestedType.PORTRAIT或OrientationRequestedType.LANDSCAPE。 - 抛出:
-
IllegalArgumentException- 如果orientationRequested为null。
-
setOrientationRequested
public void setOrientationRequested(int orientationRequested) 指定使用这些属性的页面的打印方向。指定3表示纵向。指定4表示横向。指定任何其他值将生成IllegalArgumentException。不指定属性等效于调用setOrientationRequested(OrientationRequestedType.PORTRAIT)。- 参数:
-
orientationRequested-3或4 - 抛出:
-
IllegalArgumentException- 如果orientationRequested不是3或4
-
setOrientationRequestedToDefault
public void setOrientationRequestedToDefault()将使用这些属性的页面的打印方向设置为默认。默认方向为纵向。 -
getOrigin
返回使用这些属性的页面在(0, 0)处绘制时是在物理页面的左上角绘制,还是在可打印区域的左上角绘制。 (请注意,这些位置可能是等效的。)此属性不能由实现或目标打印机修改,也不受任何限制。- 返回:
- OriginType.PHYSICAL或OriginType.PRINTABLE
-
setOrigin
指定使用这些属性的页面在(0, 0)处绘制时是在物理页面的左上角绘制,还是在可打印区域的左上角绘制。 (请注意,这些位置可能是等效的。)不指定属性等效于指定OriginType.PHYSICAL。- 参数:
-
origin- OriginType.PHYSICAL 或 OriginType.PRINTABLE - 抛出:
-
IllegalArgumentException- 如果 origin 为 null。
-
getPrintQuality
返回使用这些属性的页面的打印质量。此属性将更新为用户选择的值。- 返回:
- PrintQualityType.DRAFT, PrintQualityType.NORMAL, 或 PrintQualityType.HIGH
-
setPrintQuality
指定使用这些属性的页面的打印质量。不指定该属性等同于指定PrintQualityType.NORMAL。- 参数:
-
printQuality- PrintQualityType.DRAFT, PrintQualityType.NORMAL, 或 PrintQualityType.HIGH - 抛出:
-
IllegalArgumentException- 如果 printQuality 为 null。
-
setPrintQuality
public void setPrintQuality(int printQuality) 指定使用这些属性的页面的打印质量。指定3表示草稿。指定4表示正常。指定5表示高。指定其他任何值将生成 IllegalArgumentException。不指定该属性等同于调用 setPrintQuality(PrintQualityType.NORMAL)。- 参数:
-
printQuality-3,4, 或5 - 抛出:
-
IllegalArgumentException- 如果 printQuality 不是3,4, 或5
-
setPrintQualityToDefault
public void setPrintQualityToDefault()将使用这些属性的页面的打印质量设置为默认值。默认打印质量为正常。 -
getPrinterResolution
public int[] getPrinterResolution()返回使用这些属性的页面的打印分辨率。数组的索引 0 指定横向分辨率(通常为水平分辨率)。数组的索引 1 指定纵向分辨率(通常为垂直分辨率)。数组的索引 2 指定分辨率是每英寸还是每厘米。3表示每英寸的点数。4表示每厘米的点数。- 返回:
-
一个包含 3 个元素的整数数组。第一个元素必须大于 0。第二个元素必须大于 0。第三个元素必须是
3或4。
-
setPrinterResolution
public void setPrinterResolution(int[] printerResolution) 指定使用这些属性的页面的所需打印分辨率。实际分辨率将由实现的限制和目标打印机确定。数组的索引 0 指定横向分辨率(通常为水平分辨率)。数组的索引 1 指定纵向分辨率(通常为垂直分辨率)。数组的索引 2 指定分辨率是每英寸还是每厘米。3表示每英寸的点数。4表示每厘米的点数。请注意,1.1 版本的打印实现(Toolkit.getPrintJob)要求进纸和横向分辨率相同。不指定该属性等同于调用 setPrinterResolution(72)。- 参数:
-
printerResolution- 一个包含 3 个元素的整数数组。第一个元素必须大于 0。第二个元素必须大于 0。第三个元素必须是3或4。 - 抛出:
-
IllegalArgumentException- 如果违反上述条件中的一个或多个。
-
setPrinterResolution
public void setPrinterResolution(int printerResolution) 指定使用这些属性的页面的横向和纵向打印分辨率(每英寸的点数)。两个分辨率使用相同的值。实际分辨率将由实现的限制和目标打印机确定。不指定该属性等同于指定72。- 参数:
-
printerResolution- 大于 0 的整数。 - 抛出:
-
IllegalArgumentException- 如果 printerResolution 小于或等于 0。
-
setPrinterResolutionToDefault
public void setPrinterResolutionToDefault()将使用这些属性的页面的打印分辨率设置为默认值。默认值为横向和纵向分辨率均为 72 dpi。 -
equals
确定两个 PageAttributes 是否相等。仅当它们的每个属性都相等时,两个 PageAttributes 才相等。枚举类型的属性仅当字段引用相同的唯一枚举对象时才相等。这意味着别名媒体等于其基础唯一媒体。打印分辨率仅当进纸分辨率、横向分辨率和单位均相等时才相等。
-
hashCode
public int hashCode()返回此 PageAttributes 的哈希码值。 -
toString
返回此 PageAttributes 的字符串表示形式。
-