Hi all,
attached is the Print Preview class one of our developer used to view the printable map or any other Graphics object. This is a generic class not specificly for OpenMap but works well with OpenMap.
The object to be printed should implement the Printable interface like this:
/**
* Print method to implement pritable interface
*/
public int print(Graphics pg, PageFormat pageFormat, int pageIndex)
throws PrinterException
{
if (pageIndex >= m_maxNumPage || bufferedImage == null)
return NO_SUCH_PAGE;
pg.translate((int)pageFormat.getImageableX(),
(int)pageFormat.getImageableY());
int wPage = (int)pageFormat.getImageableWidth();
int hPage = (int)pageFormat.getImageableHeight();
int w = bufferedImage.getWidth(this);
int h = bufferedImage.getHeight(this);
if (w == 0 || h == 0)
return NO_SUCH_PAGE;
int nCol = Math.max((int)Math.ceil((double)w/wPage), 1);
int nRow = Math.max((int)Math.ceil((double)h/hPage), 1);
m_maxNumPage = nCol*nRow;
int iCol = pageIndex % nCol;
int iRow = pageIndex / nCol;
int x = iCol*wPage;
int y = iRow*hPage;
int wImage = Math.min(wPage, w-x);
int hImage = Math.min(hPage, h-y);
pg.drawImage(bufferedImage, 0, 0, wImage, hImage,
x, y, x+wImage, y+hImage, this);
System.gc();
return PAGE_EXISTS;
}
And this is how we use the PrintPreview class:
//// Create the Print button and set its listeners
toolbar.add(bt = new JButton(new ImageIcon("print.gif")));
bt.setPreferredSize(dim);
bt.setToolTipText("Print");
bt.setFocusPainted(false);
final MapView thisView = this;
bt.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (drawOnBufferedImage())
{
Thread runner = new Thread() {
public void run(){
new PrintPreview(thisView, "Network View preview", true);
}
};
runner.start();
}
else
{
JOptionPane.showMessageDialog(thisView,
"Nothing to print or the image is too big to print, try zoom out first.","Error Message"
JOptionPane.INFORMATION_MESSAGE);
return;
}
}
});
///////////////// Done with the Print button
Let me know if it does or does not work for you.
-Chinh
Ken Anderson wrote:
> I'm not an openmap developer, and I haven't printed myself, but Rich Shapiro has. I think getting transformations and clipping right can be tricky. Maybe sending us your code or trying random algorithms might help.
>
> k
>
> At 01:13 AM 6/29/2001, Tennessee Leeuwenburg wrote:
> >Hi all,
> >
> >I've implemented printing in Openmap, but I have one persistent problem. The image I get has (obviously) the same dimensions as the map. In my case, those dimensions aren't the same aspect ratio, and are larger than, what will fit on the printable area of an a4 page. This results in clipping. I've found that rescaling the image will rescale my printed output, but not actually change where the image is being clipped. (i.e. my output changes size/ratio, but only the clipped output appear, even though the new size would be large enough to accommodate the entire image. Any ideas anyone?
> >
> >-Tennessee
> >==============================================
> >This email contains information which may be useful. The views
> >expressed within may or may not be the views of the author.
> >==============================================
> >
> >-Tennessee Leeuwenburg, Silver Stream Pty Ltd
> >0418 300 881
> >
> >--
> >[To unsubscribe to this list send an email to "majdart@bbn.com"
> >with the following text in the BODY of the message "unsubscribe openmap-users"]
> >
>
> --
> [To unsubscribe to this list send an email to "majdart@bbn.com"
> with the following text in the BODY of the message "unsubscribe openmap-users"]
-- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:31 EDT