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


Java PageFormat.getImageableHeight方法代码示例

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


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

示例1: scaleToFitY

import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
 * Set the print size to fit a page in the verticle direction.
 * The horizontal is scaled equally but no garuntees are made on the page fit.
 */
private void scaleToFitY() {
    PageFormat format = getPageFormat();
    Rectangle componentBounds = scene.getBounds();

    if (componentBounds.height == 0) {
        return;
    }

    double scaleY = format.getImageableHeight() / componentBounds.height;
    double scaleX = scaleY;
    if (scaleY < 1) {
        setSize((float) (componentBounds.width * scaleX), (float) format.getImageableHeight());
        setScaledSize(scaleX, scaleY);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:PageableScene.java

示例2: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
 * Print the plot to a printer, represented by the specified graphics
 * object.
 *
 * @param graphics The context into which the page is drawn.
 * @param format The size and orientation of the page being drawn.
 * @param index The zero based index of the page to be drawn.
 * @return PAGE_EXISTS if the page is rendered successfully, or
 * NO_SUCH_PAGE if pageIndex specifies a non-existent page.
 * @exception PrinterException If the print job is terminated.
 */

public synchronized int print(Graphics graphics, PageFormat format,
        int index) throws PrinterException {
    if (graphics == null) return Printable.NO_SUCH_PAGE;
    // We only print on one page.
    if (index >= 1) {
        return Printable.NO_SUCH_PAGE;
    }
    Graphics2D graphics2D = (Graphics2D) graphics;
    // Scale the printout to fit the pages.
    // Contributed by Laurent ETUR, Schlumberger Riboud Product Center
    double scalex = format.getImageableWidth() / (double) getWidth();
    double scaley = format.getImageableHeight() / (double) getHeight();
    double scale = Math.min(scalex, scaley);
    graphics2D.translate((int)format.getImageableX(),
            (int)format.getImageableY());
    graphics2D.scale(scale, scale);
    _drawPlot(graphics, true);
    return Printable.PAGE_EXISTS;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:32,代码来源:PlotBox.java

示例3: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
 * Prints the chart on a single page.
 *
 * @param g  the graphics context.
 * @param pf  the page format to use.
 * @param pageIndex  the index of the page. If not <code>0</code>, nothing 
 *                   gets print.
 *
 * @return The result of printing.
 */
public int print(Graphics g, PageFormat pf, int pageIndex) {

    if (pageIndex != 0) {
        return NO_SUCH_PAGE;
    }
    Graphics2D g2 = (Graphics2D) g;
    double x = pf.getImageableX();
    double y = pf.getImageableY();
    double w = pf.getImageableWidth();
    double h = pf.getImageableHeight();
    this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor, 
            null);
    return PAGE_EXISTS;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:26,代码来源:ChartPanel.java

示例4: scaleToFit

import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
 * Adjusts the scaling factors in both the horizontal and vertical directions
 * to garuntee that the Scene prints onto a single page.
 * @param useSymmetricScaling if true, the horizontal and vertical scaling
 * factors will be the same whereby preserving the current aspect ration. The
 * smallest of the two (horizontal and vertical) scaling factors is used for 
 * both.
 */
private void scaleToFit(boolean useSymmetricScaling) {
    PageFormat format = getPageFormat();

    Rectangle componentBounds = scene.getView().getBounds();

    if (componentBounds.width * componentBounds.height == 0) {
        return;
    }
    double scaleX = format.getImageableWidth() / componentBounds.width;
    double scaleY = format.getImageableHeight() / componentBounds.height;

    if (scaleX < 1 || scaleY < 1) {

        if (useSymmetricScaling) {
            if (scaleX < scaleY) {
                scaleY = scaleX;
            } else {
                scaleX = scaleY;
            }
        }

        setSize((float) (componentBounds.width * scaleX), (float) (componentBounds.height * scaleY));
        setScaledSize(scaleX, scaleY);

    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:PageableScene.java

示例5: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
 * Prints the chart on a single page.
 * 
 * @param g
 *            the graphics context.
 * @param pf
 *            the page format to use.
 * @param pageIndex
 *            the index of the page. If not <code>0</code>, nothing gets print.
 * 
 * @return The result of printing.
 */

@Override
public int print(Graphics g, PageFormat pf, int pageIndex) {

	if (pageIndex != 0) {
		return NO_SUCH_PAGE;
	}
	Graphics2D g2 = (Graphics2D) g;
	double x = pf.getImageableX();
	double y = pf.getImageableY();
	double w = pf.getImageableWidth();
	double h = pf.getImageableHeight();
	this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null);
	return PAGE_EXISTS;

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:29,代码来源:AbstractChartPanel.java

示例6: printHeaderFooter

import java.awt.print.PageFormat; //导入方法依赖的package包/类
private void printHeaderFooter(Graphics g, PageFormat pageFormat, int page, String className)
{
    int origPage = page+1;

    // Add header
    g.setColor(Color.BLACK);
    int xOffset = (int)pageFormat.getImageableX();
    int topOffset = (int)pageFormat.getImageableY()+20;
    int bottom = (int)(pageFormat.getImageableY()+pageFormat.getImageableHeight());
    // header line
    g.drawLine(xOffset, topOffset-8, xOffset+(int)pageFormat.getImageableWidth(), topOffset-8);
    // footer line
    g.drawLine(xOffset,                                    bottom-11,
              xOffset+(int)pageFormat.getImageableWidth(), bottom-11);
    g.setFont(new Font(Font.SANS_SERIF,Font.ITALIC,10));

    Graphics2D gg = (Graphics2D) g;
    String pageString = "Page "+origPage;
    int tw = (int) gg.getFont().getStringBounds(pageString,gg.getFontRenderContext()).getWidth();
    
    // header text
    if(className!=null)
        g.drawString(className, xOffset, topOffset-10);
    // footer text
    g.drawString(pageString, xOffset+(int)pageFormat.getImageableWidth()-tw,bottom-2);
}
 
开发者ID:fesch,项目名称:Moenagade,代码行数:27,代码来源:BloxsEditor.java

示例7: getPainter

import java.awt.print.PageFormat; //导入方法依赖的package包/类
private PIDEF0painter getPainter(final int index) {
    if (painters[index] == null) {
        final PageFormat pf = getPageFormat();
        int imageableWidth = (int) pf.getImageableWidth();

        String size = functions[index].getPageSize();
        int h;
        int pc = 1;
        if (size != null && (h = size.indexOf('x')) >= 0)
            pc = Integer.parseInt(size.substring(h + 1));

        imageableWidth *= pc;
        painters[index] = new PIDEF0painter(
                functions[index],
                new Dimension(imageableWidth, (int) pf.getImageableHeight()),
                dataPlugin, pc);
        if (nativeTextPaint)
            painters[index].getMovingArea().setNativePaint(true);
    }
    return painters[index];
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:22,代码来源:IDEF0Printable.java

示例8: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat pf, int index) {

        if (index > 0 || image == null) {
            return Printable.NO_SUCH_PAGE;
        }

        ((Graphics2D)g).translate(pf.getImageableX(), pf.getImageableY());
        int w = image.getWidth(null);
        int h = image.getHeight(null);
        int iw = (int)pf.getImageableWidth();
        int ih = (int)pf.getImageableHeight();

        // ensure image will fit
        int dw = w;
        int dh = h;
        if (dw > iw) {
            dh = (int)(dh * ( (float) iw / (float) dw)) ;
            dw = iw;
        }
        if (dh > ih) {
            dw = (int)(dw * ( (float) ih / (float) dh)) ;
            dh = ih;
        }
        // centre on page
        int dx = (iw - dw) / 2;
        int dy = (ih - dh) / 2;

        g.drawImage(image, dx, dy, dx+dw, dy+dh, 0, 0, w, h, null);
        return Printable.PAGE_EXISTS;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:ImagePrinter.java

示例9: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
@Override
public int print(Graphics g, PageFormat format, int index) throws PrinterException {
    int pagenum = index + 1;
    if ((pagenum >= 1) && (pagenum <= file.getNumPages())) {
        Graphics2D g2 = (Graphics2D) g;

        PDFPage page = file.getPage(pagenum);

        Rectangle imageArea = new Rectangle((int) format.getImageableX(), (int) format.getImageableY(),
                (int) format.getImageableWidth() , (int) format.getImageableHeight());
        g2.translate(0, 0);
        PDFRenderer pgs = new PDFRenderer(page, g2, imageArea, null, null);
        try {

            page.waitForFinish();

            pgs.run();
        } catch (InterruptedException ie) {
            System.out.println(ie.toString());
        }
        return PAGE_EXISTS;
    } else {
        return NO_SUCH_PAGE;
    }
}
 
开发者ID:JIGAsoftSTP,项目名称:NICON,代码行数:26,代码来源:PrintPdf.java

示例10: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
 * Prints the chart on a single page.
 *
 * @param g  the graphics context.
 * @param pf  the page format to use.
 * @param pageIndex  the index of the page. If not <code>0</code>, nothing gets print.
 *
 * @return the result of printing.
 */
public int print(Graphics g, PageFormat pf, int pageIndex) {

    if (pageIndex != 0) {
        return NO_SUCH_PAGE;
    }
    Graphics2D g2 = (Graphics2D) g;
    double x = pf.getImageableX();
    double y = pf.getImageableY();
    double w = pf.getImageableWidth();
    double h = pf.getImageableHeight();
    this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null);
    return PAGE_EXISTS;

}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:ChartPanel.java

示例11: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat fmt, int pageNo) {
	printing = true;
	if( pageNo>1 ) {
		printing = false;
		return NO_SUCH_PAGE;
	}
	Rectangle r = getVisibleRect();
	double w = fmt.getImageableWidth();
	double h = fmt.getImageableHeight();
	double x = fmt.getImageableX();
	double y = fmt.getImageableY();
	Insets ins = axes.getInsets();
	double ww = w - ins.left - ins.right;
	double hh = h - ins.top - ins.bottom;
	double rw = (double)(r.width - ins.left - ins.right);
	double rh = (double)(r.height - ins.top - ins.bottom);
	double scale = Math.min( rh/rw, rw/rh);
	double newH = ww * scale;
	double newW = hh * scale;
	if( !tracksWidth || !tracksHeight ) {
		int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
		scale = 72./dpi;
	}
	newW = rw*scale;
	newH = rh*scale;
	x -= (newW-ww)/2;
	y -= (newH-hh)/2;
	w = newW + ins.left + ins.right;
	h = newH +ins.top + ins.bottom;
	printRect = new Rectangle( (int)x,
				(int)y,
				(int)w,
				(int)h );
	paintComponent(g);
	printing = false;
	return PAGE_EXISTS;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:38,代码来源:XYGraph.java

示例12: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat pf, int pi)
        throws PrinterException {
    if (pi != 0) {
        return NO_SUCH_PAGE;
    }
    Graphics2D g2 = (Graphics2D) g;
    g2.setFont(new Font("Serif", Font.PLAIN, 36));
    g2.setPaint(Color.black);
    g2.drawString("Java Source and Support", 100, 100);
    Rectangle2D outline = new Rectangle2D.Double(pf.getImageableX(), pf
            .getImageableY(), pf.getImageableWidth(), pf
            .getImageableHeight());
    g2.draw(outline);
    return PAGE_EXISTS;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:PrintTestLexmarkIQ.java

示例13: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat pageFormat, int pageIndex)
{
    final int boxWidth = 100;
    final int boxHeight = 100;
    final Rectangle rect = new Rectangle(0,0,boxWidth,boxHeight);
    final double pageH = pageFormat.getImageableHeight();
    final double pageW = pageFormat.getImageableWidth();

    if (pageIndex > 0) return (NO_SUCH_PAGE);

    final Graphics2D g2d = (Graphics2D)g;

    // Move the (x,y) origin to account for the left-hand and top margins
    g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

    // Draw the page bounding box
    g2d.drawRect(0,0,(int)pageW,(int)pageH);

    // Select the smaller scaling factor so that the figure
    // fits on the page in both dimensions
    final double scale = Math.min( (pageW/boxWidth), (pageH/boxHeight) );

    if(scale < 1.0) g2d.scale(scale, scale);

    // Paint the scaled component on the printer
    g2d.fillRect(rect.x, rect.y, rect.width, rect.height);

    return(PAGE_EXISTS);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:PageDlgPrnButton.java

示例14: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
public int print(Graphics g, PageFormat fmt, int pageNo) {
	printing = true;
	if( pageNo>1 ) {
		printing = false;
		return NO_SUCH_PAGE;
	}
	Graphics2D g2 = (Graphics2D)g;
	Dimension dim = getPreferredSize();
	Rectangle r = getVisibleRect();
//	if(r.width>dim.width) r.width = dim.width;
//	if(r.height>dim.height) r.height = dim.height;
	double w = fmt.getImageableWidth();
	double h = fmt.getImageableHeight();
	double x = fmt.getImageableX();
	double y = fmt.getImageableY();
	Insets ins = axes.getInsets();
	double ww = w - ins.left - ins.right;
	double hh = h - ins.top - ins.bottom;
	double rw = (double)(r.width - ins.left - ins.right);
	double rh = (double)(r.height - ins.top - ins.bottom);
	double scale = Math.min( rh/rw, rw/rh);
	double newH = ww * scale;
	double newW = hh * scale;
	if( !tracksWidth || !tracksHeight ) {
		int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
		scale = 72./dpi;
	}
	newW = rw*scale;
	newH = rh*scale;
	x -= (newW-ww)/2;
	y -= (newH-hh)/2;
	w = newW + ins.left + ins.right;
	h = newH +ins.top + ins.bottom;
	printRect = new Rectangle( (int)x,
				(int)y,
				(int)w,
				(int)h );
	paintComponent(g);
	printing = false;
	return PAGE_EXISTS;
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:42,代码来源:XYGraph.java

示例15: print

import java.awt.print.PageFormat; //导入方法依赖的package包/类
@Override
public int print(Graphics base, PageFormat format, int pageIndex) {
	if (pageIndex >= circuits.size())
		return Printable.NO_SUCH_PAGE;

	Circuit circ = circuits.get(pageIndex);
	CircuitState circState = proj.getCircuitState(circ);
	Graphics g = base.create();
	Graphics2D g2 = g instanceof Graphics2D ? (Graphics2D) g : null;
	FontMetrics fm = g.getFontMetrics();
	String head = (header != null && !header.equals(""))
			? format(header, pageIndex + 1, circuits.size(), circ.getName())
			: null;
	int headHeight = (head == null ? 0 : fm.getHeight());

	// Compute image size
	double imWidth = format.getImageableWidth();
	double imHeight = format.getImageableHeight();

	// Correct coordinate system for page, including
	// translation and possible rotation.
	Bounds bds = circ.getBounds(g).expand(4);
	double scale = Math.min(imWidth / bds.getWidth(), (imHeight - headHeight) / bds.getHeight());
	if (g2 != null) {
		g2.translate(format.getImageableX(), format.getImageableY());
		if (rotateToFit && scale < 1.0 / 1.1) {
			double scale2 = Math.min(imHeight / bds.getWidth(), (imWidth - headHeight) / bds.getHeight());
			if (scale2 >= scale * 1.1) { // will rotate
				scale = scale2;
				if (imHeight > imWidth) { // portrait -> landscape
					g2.translate(0, imHeight);
					g2.rotate(-Math.PI / 2);
				} else { // landscape -> portrait
					g2.translate(imWidth, 0);
					g2.rotate(Math.PI / 2);
				}
				double t = imHeight;
				imHeight = imWidth;
				imWidth = t;
			}
		}
	}

	// Draw the header line if appropriate
	if (head != null) {
		g.drawString(head, (int) Math.round((imWidth - fm.stringWidth(head)) / 2), fm.getAscent());
		if (g2 != null) {
			imHeight -= headHeight;
			g2.translate(0, headHeight);
		}
	}

	// Now change coordinate system for circuit, including
	// translation and possible scaling
	if (g2 != null) {
		if (scale < 1.0) {
			g2.scale(scale, scale);
			imWidth /= scale;
			imHeight /= scale;
		}
		double dx = Math.max(0.0, (imWidth - bds.getWidth()) / 2);
		g2.translate(-bds.getX() + dx, -bds.getY());
	}

	// Ensure that the circuit is eligible to be drawn
	Rectangle clip = g.getClipBounds();
	clip.add(bds.getX(), bds.getY());
	clip.add(bds.getX() + bds.getWidth(), bds.getY() + bds.getHeight());
	g.setClip(clip);

	// And finally draw the circuit onto the page
	ComponentDrawContext context = new ComponentDrawContext(proj.getFrame().getCanvas(), circ, circState, base,
			g, printerView);
	Collection<Component> noComps = Collections.emptySet();
	circ.draw(context, noComps);
	g.dispose();
	return Printable.PAGE_EXISTS;
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:79,代码来源:Print.java


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