Google Answers Logo
View Question
 
Q: Programming Print Preview in Java ( No Answer,   0 Comments )
Question  
Subject: Programming Print Preview in Java
Category: Computers > Programming
Asked by: asdf123-ga
List Price: $40.00
Posted: 28 Feb 2005 12:46 PST
Expires: 01 Mar 2005 09:58 PST
Question ID: 482434
I need to program a fairly straight forward print preview 
function (in java) for a program i am writing.

There are two parts -  how to scale the graphics for printing +
the actual presentation of the graphics in a print preview

I am a competent java programmer so explanation of the gui is not
necessary. 

These are the specifics of how it should work:
I have a class "MakeDrawing(Graphics g)". it is passed a Graphics g
(NOT Graphics2d) and draws onto it. Usually the drawing will be 1028*768
but it could be smaller (or possibly larger i guess).
I need to know how to manipulate this picture - i am NOT competent with 
graphics2d and need to know how to use it - especially to "scale to
fit" this for an 8.5 * 11 page with BOTH landscape
and portrait functionality.

The print preview gui will be as follows.
A Jinternal frame.
Two radio buttons - landscape, portrait
2 textfields for x and y scaling
a button for scale to fit (it will set those 2 x and y textfields appropraitely
a check box for constrain proportions for scale to fit
a button for print 
and a JPanel (340 by 440 - 40 pixels per inch) that will contain the
print preview image.

I do not want any of that gui implementation. I mentioned it
so you will have an idea of  the functionality required and the
JPanel size used and get a general idea of how this will all 
come together.

So this is what i need -
the implementation of that JPanel that will display what the printed
page will look like.
and the methods to manipulate the image for those desired features for
printing. to draw the image call my Make.Drawing(g) class and method.

i have a fit to page and printing method written now but it doesnt 
look good when printed and i dont really fully understand whats going on.

I need to understand printing space versus pixels. What imageable space is.
how to calculate and understand how a graphics object is displayed on
the printed page.

This is EXTREMELY time critical. if $40 is not enough im willing to 
pay more for a fast and explanatory answer.
This is important. Im looking forward to getting a good answer.
-------------
this is the method i have so far
i got it off the internet
it is not important to keep this.
i just wanted to give an example of what i had.
completely scarp this or rewrite it as necessary.

public int print(Graphics g, PageFormat format, int pageIndex) {
format.setOrientation(format.PORTRAIT);
Graphics2D g2D = (Graphics2D) g;
g2D.translate(format.getImageableX (), format.getImageableY ());
disableDoubleBuffering(this);
// scale to fill the page
double dw = format.getImageableWidth();
double dh = format.getImageableHeight();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
double xScale = dw / (double)( PS.plen+150 );
double yScale = dh / (double)( PS.pht+50 );
double scale = Math.min(xScale,yScale);

g2D.scale( xScale, yScale);
// for constrain proportions it would have been
// g2D.scale (scale, scale) - the minimum of xscale and yscale

Make.Drawing( g);
enableDoubleBuffering(this);
return Printable.PAGE_EXISTS;
}
public void disableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(false);
}

public void enableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(true);
}

Clarification of Question by asdf123-ga on 28 Feb 2005 13:00 PST
It might be necessary to mention that i am NOT looking for links to 
websites as an answer nor am i strictly looking for exact code.
Easy to understand psuedo code and an explanation is good enough.
Id like an explanation of how to use graphics2d (to be fair to you,
only in as much as it is pertinent to the question).
From what i read scale, and affine transform, etc are used to acheive
what is desired here.
And most importantly just keep it simple and dont let my rambling make this
question appear too complicated, haha. 
Thank You!
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy