本文整理汇总了Java中javax.print.attribute.AttributeSet.add方法的典型用法代码示例。如果您正苦于以下问题:Java AttributeSet.add方法的具体用法?Java AttributeSet.add怎么用?Java AttributeSet.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.print.attribute.AttributeSet
的用法示例。
在下文中一共展示了AttributeSet.add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
@Override
public void create(String filename) {
// find the printing service
//http://www.coderanch.com/t/385989/java/java/send-raw-data-printer
AttributeSet attributeSet = new HashAttributeSet();
attributeSet.add(new PrinterName(filename, null));
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attributeSet);
if(services.length > 0){
if(printFile != null){
printFile.deleteOnExit();
printFile = null;
}
try {
printFile = File.createTempFile("printer_"+name,".redirect");
} catch (IOException e) {
e.printStackTrace();
}
printService = services[0];
}
}
示例2: getUnsupportedAttributes
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
public AttributeSet getUnsupportedAttributes(final DocFlavor flavor,
final AttributeSet attributes) {
checkFlavor(flavor);
if (attributes == null) {
return null;
}
final AttributeSet result = new HashAttributeSet();
for (Attribute attr : attributes.toArray()) {
if (!isAttributeValueSupported(attr, flavor, attributes)) {
result.add(attr);
}
}
return result.size() > 0 ? result : null;
}
示例3: getUnsupportedAttributes
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
AttributeSet attributes) {
if (flavor != null && !isDocFlavorSupported(flavor)) {
throw new IllegalArgumentException("flavor " + flavor +
"is not supported");
}
if (attributes == null) {
return null;
}
Attribute attr;
AttributeSet unsupp = new HashAttributeSet();
Attribute[] attrs = attributes.toArray();
for (int i=0; i<attrs.length; i++) {
try {
attr = attrs[i];
if (!isAttributeCategorySupported(attr.getCategory())) {
unsupp.add(attr);
} else if (!isAttributeValueSupported(attr, flavor,
attributes)) {
unsupp.add(attr);
}
} catch (ClassCastException e) {
}
}
if (unsupp.isEmpty()) {
return null;
} else {
return unsupp;
}
}
示例4: removeUnsupportedAttributes
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
/**
* Removes any attributes from the given AttributeSet that are
* unsupported by the given PrintService/DocFlavor combination.
*/
private static void removeUnsupportedAttributes(PrintService ps,
DocFlavor flavor,
AttributeSet aset)
{
AttributeSet asUnsupported = ps.getUnsupportedAttributes(flavor,
aset);
if (asUnsupported != null) {
Attribute[] usAttrs = asUnsupported.toArray();
for (int i=0; i<usAttrs.length; i++) {
Class category = usAttrs[i].getCategory();
if (ps.isAttributeCategorySupported(category)) {
Attribute attr =
(Attribute)ps.getDefaultAttributeValue(category);
if (attr != null) {
aset.add(attr);
} else {
aset.remove(category);
}
} else {
aset.remove(category);
}
}
}
}
示例5: getUnsupportedAttributes
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
AttributeSet attributes) {
if (flavor != null && !isDocFlavorSupported(flavor)) {
throw new IllegalArgumentException("flavor " + flavor +
"is not supported");
}
if (attributes == null) {
return null;
}
Attribute attr;
AttributeSet unsupp = new HashAttributeSet();
Attribute []attrs = attributes.toArray();
for (int i=0; i<attrs.length; i++) {
try {
attr = attrs[i];
if (!isAttributeCategorySupported(attr.getCategory())) {
unsupp.add(attr);
}
else if (!isAttributeValueSupported(attr, flavor, attributes)) {
unsupp.add(attr);
}
} catch (ClassCastException e) {
}
}
if (unsupp.isEmpty()) {
return null;
} else {
return unsupp;
}
}
示例6: getUnsupportedAttributes
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
AttributeSet attributes) {
if (flavor != null && !isDocFlavorSupported(flavor)) {
throw new IllegalArgumentException("flavor " + flavor +
"is not supported");
}
if (attributes == null) {
return null;
}
Attribute attr;
AttributeSet unsupp = new HashAttributeSet();
Attribute []attrs = attributes.toArray();
for (int i=0; i<attrs.length; i++) {
try {
attr = attrs[i];
if (!isAttributeCategorySupported(attr.getCategory())) {
unsupp.add(attr);
} else if (!isAttributeValueSupported(attr, flavor,
attributes)) {
unsupp.add(attr);
}
} catch (ClassCastException e) {
}
}
if (unsupp.isEmpty()) {
return null;
} else {
return unsupp;
}
}
示例7: lookupByName
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
private static PrintService lookupByName(String name) {
AttributeSet attributes = new HashAttributeSet();
attributes.add(new PrinterName(name, null));
for (PrintService service : PrintServiceLookup.lookupPrintServices(null, attributes)) {
return service;
}
return null;
}
示例8: removeUnsupportedAttributes
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
/**
* Removes any attributes from the given {@code AttributeSet} that are
* unsupported by the given {@code PrintService/DocFlavor} combination.
*/
private static void removeUnsupportedAttributes(PrintService ps,
DocFlavor flavor,
AttributeSet aset)
{
AttributeSet asUnsupported = ps.getUnsupportedAttributes(flavor,
aset);
if (asUnsupported != null) {
Attribute[] usAttrs = asUnsupported.toArray();
for (int i=0; i<usAttrs.length; i++) {
Class<? extends Attribute> category = usAttrs[i].getCategory();
if (ps.isAttributeCategorySupported(category)) {
Attribute attr =
(Attribute)ps.getDefaultAttributeValue(category);
if (attr != null) {
aset.add(attr);
} else {
aset.remove(category);
}
} else {
aset.remove(category);
}
}
}
}
示例9: getUnsupportedAttributes
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
public AttributeSet getUnsupportedAttributes(DocFlavor flavor,
AttributeSet attributes) {
if (flavor != null && !isDocFlavorSupported(flavor)) {
throw new IllegalArgumentException("flavor " + flavor +
" is not supported");
}
if (attributes == null) {
return null;
}
Attribute attr;
AttributeSet unsupp = new HashAttributeSet();
Attribute []attrs = attributes.toArray();
for (int i=0; i<attrs.length; i++) {
try {
attr = attrs[i];
if (!isAttributeCategorySupported(attr.getCategory())) {
unsupp.add(attr);
}
else if (!isAttributeValueSupported(attr, flavor, attributes)) {
unsupp.add(attr);
}
} catch (ClassCastException e) {
}
}
if (unsupp.isEmpty()) {
return null;
} else {
return unsupp;
}
}
示例10: lookupByName
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
private static PrintService lookupByName(String name) {
AttributeSet attributes = new HashAttributeSet();
attributes.add(new PrinterName(name, null));
for (PrintService service :
PrintServiceLookup.lookupPrintServices(null, attributes)) {
return service;
}
return null;
}
示例11: removeUnsupportedAttributes
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
/**
* Removes any attributes from the given AttributeSet that are
* unsupported by the given PrintService/DocFlavor combination.
*/
private static void removeUnsupportedAttributes(PrintService ps,
DocFlavor flavor,
AttributeSet aset)
{
AttributeSet asUnsupported = ps.getUnsupportedAttributes(flavor,
aset);
if (asUnsupported != null) {
Attribute[] usAttrs = asUnsupported.toArray();
for (int i=0; i<usAttrs.length; i++) {
Class<? extends Attribute> category = usAttrs[i].getCategory();
if (ps.isAttributeCategorySupported(category)) {
Attribute attr =
(Attribute)ps.getDefaultAttributeValue(category);
if (attr != null) {
aset.add(attr);
} else {
aset.remove(category);
}
} else {
aset.remove(category);
}
}
}
}
示例12: testIsAttributeValueSupported
import javax.print.attribute.AttributeSet; //导入方法依赖的package包/类
public void testIsAttributeValueSupported() throws Exception {
System.out
.println("============= START GetUnsupportedAttributesTest ================");
PrintService[] services;
DocFlavor[] flavors = new DocFlavor[] { DocFlavor.INPUT_STREAM.GIF,
DocFlavor.INPUT_STREAM.POSTSCRIPT,
DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII };
services = PrintServiceLookup.lookupPrintServices(null, null);
TestUtil.checkServices(services);
if (services.length > 0) {
for (int i = 0, ii = services.length; i < ii; i++) {
System.out.println("----------- " + services[i].getName()
+ "----------");
URI uri = null;
try {
uri = new URI("file:///c:/no/such/dir/print.out");
//uri = File.createTempFile("xxx", null).toURI();
} catch (URISyntaxException e) {
fail();
}
AttributeSet attrs = new HashAttributeSet();
attrs.add(Finishings.EDGE_STITCH);
attrs.add(MediaSizeName.JAPANESE_DOUBLE_POSTCARD);
attrs.add(new Destination(uri));
attrs.add(new DocumentName("Doc X", Locale.US));
attrs.add(new JobName("Job Y", Locale.US));
attrs.add(new RequestingUserName("User Z", Locale.US));
for (int j = 0; j < flavors.length; j++) {
if (services[i].isDocFlavorSupported(flavors[j])) {
AttributeSet aset = services[i]
.getUnsupportedAttributes(flavors[j], attrs);
if (aset == null) {
fail("At least one attribute is unsupported");
}
if (aset != null) {
Attribute[] aarr = aset.toArray();
System.out
.println("Usupported attributes fo DocFlavor "
+ flavors[j]);
for (int k = 0, kk = aarr.length; k < kk; k++) {
System.out.println("\t" + aarr[k]);
}
}
}
}
}
}
System.out
.println("============= END GetUnsupportedAttributesTest ================");
}