当前位置: 首页>>代码示例>>Java>>正文


Java MediaSize.getMediaSizeForName方法代码示例

本文整理汇总了Java中javax.print.attribute.standard.MediaSize.getMediaSizeForName方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSize.getMediaSizeForName方法的具体用法?Java MediaSize.getMediaSizeForName怎么用?Java MediaSize.getMediaSizeForName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.print.attribute.standard.MediaSize的用法示例。


在下文中一共展示了MediaSize.getMediaSizeForName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doTest

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:WrongPaperPrintingTest.java

示例2: getAllPrintableAreas

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
private MediaPrintableArea[] getAllPrintableAreas() {

        if (mpas == null) {
            Media[] media = (Media[])getSupportedAttributeValues(Media.class,
                                                                 null, null);
            mpas = new MediaPrintableArea[media.length];
            for (int i=0; i< mpas.length; i++) {
                if (media[i] instanceof MediaSizeName) {
                    MediaSizeName msn = (MediaSizeName)media[i];
                    MediaSize mediaSize = MediaSize.getMediaSizeForName(msn);
                    if (mediaSize == null) {
                        mpas[i] = (MediaPrintableArea)
                            getDefaultAttributeValue(MediaPrintableArea.class);
                    } else {
                        mpas[i] = new MediaPrintableArea(0.25f, 0.25f,
                                        mediaSize.getX(MediaSize.INCH)-0.5f,
                                        mediaSize.getY(MediaSize.INCH)-0.5f,
                                        MediaSize.INCH);
                    }
                }
            }
        }
        MediaPrintableArea[] mpasCopy = new MediaPrintableArea[mpas.length];
        System.arraycopy(mpas, 0, mpasCopy, 0, mpas.length);
        return mpasCopy;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:UnixPrintService.java

示例3: getWin32MediaAttrib

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
/** MediaSizeName / dmPaper */
private int[] getWin32MediaAttrib() {
    int wid_ht[] = {0, 0};
    if (attributes != null) {
        Media media = (Media)attributes.get(Media.class);
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize ms = MediaSize.getMediaSizeForName(msn);
            if (ms != null) {
                wid_ht[0] = (int)(ms.getX(MediaSize.INCH) * 72.0);
                wid_ht[1] = (int)(ms.getY(MediaSize.INCH) * 72.0);
            }
        }
    }
    return wid_ht;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:WPrinterJob.java

示例4: getWin32MediaAttrib

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
/** MediaSizeName / dmPaper */
private final int[] getWin32MediaAttrib() {
    int wid_ht[] = {0, 0};
    if (attributes != null) {
        Media media = (Media)attributes.get(Media.class);
        if (media instanceof MediaSizeName) {
            MediaSizeName msn = (MediaSizeName)media;
            MediaSize ms = MediaSize.getMediaSizeForName(msn);
            if (ms != null) {
                wid_ht[0] = (int)(ms.getX(MediaSize.INCH) * 72.0);
                wid_ht[1] = (int)(ms.getY(MediaSize.INCH) * 72.0);
            }
        }
    }
    return wid_ht;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:WPrinterJob.java

示例5: CPaper

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
/**
 * 	Constructor.
 *  Derive Paper from PageForamt
 * 	@param pf PageFormat
 */
public CPaper (PageFormat pf)
{
	super();
	m_landscape = pf.getOrientation() != PageFormat.PORTRAIT;
	//	try to find MediaSize
	float x = (float)pf.getWidth();
	float y = (float)pf.getHeight();
	MediaSizeName msn = MediaSize.findMedia (x/72, y/72, MediaSize.INCH);
	MediaSize ms = null;
	if (msn == null)
		msn = MediaSize.findMedia (y/72, x/72, MediaSize.INCH);	//	flip it
	if (msn != null)
		ms = MediaSize.getMediaSizeForName(msn);
	setMediaSize(ms, m_landscape);
	//	set size directly
	setSize(pf.getWidth(), pf.getHeight());
	setImageableArea(pf.getImageableX(), pf.getImageableY(),
		pf.getImageableWidth(), pf.getImageableHeight());
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:25,代码来源:CPaper.java

示例6: CustomMediaSizeName

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
public CustomMediaSizeName(String name, String choice,
                           float width, float length) {
    super(nextValue(name));
    choiceName = choice;
    customEnumTable.add(this);
    mediaName = null;
    try {
        mediaName = MediaSize.findMedia(width, length,
                                        MediaSize.INCH);
    } catch (IllegalArgumentException iae) {
    }
    // The public API method finds a closest match even if it not
    // all that close. Here we want to be sure its *really* close.
    if (mediaName != null) {
        MediaSize sz = MediaSize.getMediaSizeForName(mediaName);
        if (sz == null) {
            mediaName = null;
        } else {
            float w = sz.getX(MediaSize.INCH);
            float h = sz.getY(MediaSize.INCH);
            float dw = Math.abs(w - width);
            float dh = Math.abs(h - length);
            if (dw > 0.1 || dh > 0.1) {
                mediaName = null;
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:CustomMediaSizeName.java

示例7: mapMedia

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
public static MediaSizeName mapMedia(MediaType mType) {
    MediaSizeName media = null;

    // JAVAXSIZES.length and SIZES.length must be equal!
    // Attempt to recover by getting the smaller size.
    int length = Math.min(SIZES.length, JAVAXSIZES.length);

    for (int i=0; i < length; i++) {
        if (SIZES[i] == mType) {
            if ((JAVAXSIZES[i] != null) &&
                MediaSize.getMediaSizeForName(JAVAXSIZES[i]) != null) {
                media = JAVAXSIZES[i];
                break;
            } else {
                /* create Custom Media */
                media = new CustomMediaSizeName(SIZES[i].toString());

                float w = (float)Math.rint(WIDTHS[i]  / 72.0);
                float h = (float)Math.rint(LENGTHS[i] / 72.0);
                if (w > 0.0 && h > 0.0) {
                    // add new created MediaSize to our static map
                    // so it will be found when we call findMedia
                    new MediaSize(w, h, Size2DSyntax.INCH, media);
                }

                break;
            }
        }
    }
    return media;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:PrintJob2D.java

示例8: main

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
public static void main(String args[]) {
    MediaSize sizeA = MediaSize.getMediaSizeForName(MediaSizeName.A);
    new MediaSize(1.0f, 2.0f, MediaSize.MM, MediaSizeName.A);
    if (!sizeA.equals(MediaSize.getMediaSizeForName(MediaSizeName.A))) {
         throw new RuntimeException("mapping changed");
    }
    MediaSize sizeB = MediaSize.getMediaSizeForName(MediaSizeName.B);
    new MediaSize(1, 2, MediaSize.MM, MediaSizeName.B);
    if (!sizeB.equals(MediaSize.getMediaSizeForName(MediaSizeName.B))) {
         throw new RuntimeException("mapping changed");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:MediaMappingsTest.java

示例9: getMediaSize

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
@Override
    protected MediaSize getMediaSize(Media media, PrintService service,
            PageFormat page) {
        if (media == null || !(media instanceof MediaSizeName)) {
            return getDefaultMediaSize(page);
}
        MediaSize size = MediaSize.getMediaSizeForName((MediaSizeName) media);
        return size != null ? size : getDefaultMediaSize(page);
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:CPrinterJob.java

示例10: print

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
private void print(final PrintPackageRequest request) throws PrinterException
{
	logger.log(Level.FINE, "Printing request {}", request);

	// Create Print Job
	final PrinterJob pjob = PrinterJob.getPrinterJob();
	pjob.setJobName(request.getPrintJobName());

	final PageFormat pf = pjob.defaultPage();
	final Paper paper = pjob.defaultPage().getPaper();
	final MediaSize size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A4);

	paper.setSize(size.getSize(Size2DSyntax.INCH)[0] * 72, size.getSize(Size2DSyntax.INCH)[1] * 72);
	paper.setImageableArea(0, 0, size.getSize(Size2DSyntax.INCH)[0] * 72, size.getSize(Size2DSyntax.INCH)[1] * 72);
	pf.setPaper(paper);

	final Book book = new Book();// java.awt.print.Book
	book.append(request.getPrintable(), pf, request.getNumPages());
	pjob.setPageable(book);

	pjob.setPrintService(request.getPrintService());
	pjob.print(request.getAttributes());

	// task 09618: allow us to configure the client to return an error even if everything went OK, so we can test
	final String alwaysReturnError = Context.getContext().getProperty(Context.CTX_Testing_AlwaysReturnError, Context.DEFAULT_AlwaysReturnError);
	if (Boolean.parseBoolean(alwaysReturnError))
	{
		logger.log(Level.INFO, "{} is true, so we report an error, despite the print was OK", Context.CTX_Testing_AlwaysReturnError);

		final String errorMsg = Context.getContext().getProperty(Context.CTX_Testing_ErrorMessage, Context.DEFAULT_ErrorMessage);
		throw new PrinterException(errorMsg);
	}
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:34,代码来源:PrintingEngine.java

示例11: getSupportedMediaSizes

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
private MediaSize[] getSupportedMediaSizes() {
    MediaSizeName[] mediaSizeNames = getSupportedMediaSizeNames();
    if (mediaSizeNames != null) {
        MediaSize[] mediaSizes = new MediaSize[mediaSizeNames.length];
        for (int i = 0; i < mediaSizeNames.length; i++) {
            mediaSizes[i] =
                MediaSize.getMediaSizeForName(mediaSizeNames[i]);
        }
        return mediaSizes;
    }
    return null;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:13,代码来源:GDIClient.java

示例12: getSupportedMediaSizes

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
public static MediaSize[] getSupportedMediaSizes(final long handle)
                throws PrintException {
    final MediaSizeName[] names = getSupportedMediaSizeNames(handle);
    final MediaSize[] sizes = new MediaSize[names.length];

    for (int i = 0; i < names.length; i++) {
        sizes[i] = MediaSize.getMediaSizeForName(names[i]);
    }

    return sizes;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:12,代码来源:WinPrinterFactory.java

示例13: getMediaDimensions

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
/**
 * @param media The {@link Media} to extract dimensions for.
 * @param units The units to return.
 * @return The dimensions of the specified {@link Media}.
 */
public static double[] getMediaDimensions(Media media, LengthUnits units) {
	MediaSize size = media instanceof MediaSizeName ? MediaSize.getMediaSizeForName((MediaSizeName) media) : null;

	if (size == null) {
		size = MediaSize.NA.LETTER;
	}
	return new double[] { units.convert(LengthUnits.IN, size.getX(Size2DSyntax.INCH)), units.convert(LengthUnits.IN, size.getY(Size2DSyntax.INCH)) };
}
 
开发者ID:Ayutac,项目名称:toolkit,代码行数:14,代码来源:PrintUtilities.java

示例14: addPaper

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
/**
 * Add a new paper to the list of papers
 * 
 * @param name
 * @param displayName
 */
private void addPaper(MediaSizeName name, String displayName) {
	MediaSize mSize = MediaSize.getMediaSizeForName(name);
	Paper paper = new Paper();
	paper.setSize(mSize.getX(MediaSize.MM) * ppmm, mSize.getY(MediaSize.MM)
			* ppmm);
	paperFormats.put(displayName, paper);
}
 
开发者ID:filemon,项目名称:freemind,代码行数:14,代码来源:ExportPdfPapers.java

示例15: getAttributeValues

import javax.print.attribute.standard.MediaSize; //导入方法依赖的package包/类
private void getAttributeValues(DocFlavor flavor) throws PrintException {

        Attribute attr;
        Class category;

        if (reqAttrSet.get(Fidelity.class) == Fidelity.FIDELITY_TRUE) {
            fidelity = true;
        } else {
            fidelity = false;
        }

        Attribute []attrs = reqAttrSet.toArray();
        for (int i=0; i<attrs.length; i++) {
            attr = attrs[i];
            category = attr.getCategory();
            if (fidelity == true) {
                if (!service.isAttributeCategorySupported(category)) {
                    notifyEvent(PrintJobEvent.JOB_FAILED);
                    throw new PrintJobAttributeException(
                        "unsupported category: " + category, category, null);
                } else if
                    (!service.isAttributeValueSupported(attr, flavor, null)) {
                    notifyEvent(PrintJobEvent.JOB_FAILED);
                    throw new PrintJobAttributeException(
                        "unsupported attribute: " + attr, null, attr);
                }
            }
            if (category == JobName.class) {
                jobName = ((JobName)attr).getValue();
            } else if (category == Copies.class) {
                copies = ((Copies)attr).getValue();
            } else if (category == Media.class) {
                if (attr instanceof MediaSizeName &&
                    service.isAttributeValueSupported(attr, null, null)) {
                    mediaSize =
                        MediaSize.getMediaSizeForName((MediaSizeName)attr);
                }
            } else if (category == OrientationRequested.class) {
                orient = (OrientationRequested)attr;
            }
        }
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:43,代码来源:PSStreamPrintJob.java


注:本文中的javax.print.attribute.standard.MediaSize.getMediaSizeForName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。