-
Type:
Bug
-
Resolution: Duplicate
-
Priority:
P4
-
None
-
Affects Version/s: 1.2.0
-
Component/s: client-libs
-
x86
-
windows_95
Name: dbT83986 Date: 03/02/99
Hi My self and others are wondering why bug 4149301 is closed.
Printing is very slow for simple line drawings using the 2d package.
A workaround is given "subclass graphics2d to use postscript"
but no mention of how to do this or examples is given.
-dave
###@###.###
(Review ID: 54954)
======================================================================
blaid@eng 3/11/99 - User sent code to illustrate problem
import javax.swing.*;
import java.awt.*;
import java.awt.Graphics2D;
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.print.*;
//**********************************************************************
*******
public class slowPrint{
//**********************************************************************
******
static PlotXY thePlot = new PlotXY();
//***************************
public static void main (String args[]){
//**************************
JFrame aJFrame = new JFrame("Slow Print!");
aJFrame.setSize(500,530);
//Set up menu
JMenuBar mb = new JMenuBar();
mb.add(new printMenu());
aJFrame.setJMenuBar(mb);
aJFrame.getContentPane().add(thePlot);
aJFrame.addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent e)
{
System.exit(0);
}
});
//Start the show...
aJFrame.setVisible(true);
}
//*******************************************************************
**********
static class printMenu extends JMenu {
//*******************************************************************
**********
//****************************
public printMenu(){
//****************************
super("Print");
//Add Plot Menu Item
JMenuItem m=new JMenuItem("Print");
m.addActionListener(new printActionListener());
add(m);
}
//****************************
class printActionListener implements ActionListener{
//****************************
public void actionPerformed(ActionEvent e){
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(thePlot);
if(pj.printDialog()){
try{pj.print();}
catch (PrinterException pe){
System.out.println(pe);
}
}
}
}
}
//*****************************************************************
************
static class PlotXY extends JPanel implements Printable{
//*******************************************************************
**********
//*****************************
public PlotXY(){
//*****************************
super();
//do our own initialization.
setSize(500,500);
setBackground(Color.white);
}
//*****************************
public int print(Graphics g, PageFormat pf, int pageIndex){
//*****************************
if(pageIndex !=0) return NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D) g;
pf.setOrientation(java.awt.print.PageFormat.LANDSCAPE);
Dimension d = getSize();
setSize((int)pf.getImageableWidth(),(int)pf.getImageableHeigh
t());
g2.translate(pf.getImageableX(),pf.getImageableY());
paint(g2);
setSize(d);
return PAGE_EXISTS;
}
//***************************************************************
public void paint(Graphics g){
//***************************************************************
//First call parent object paint function
super.paint(g);
//Obligitory conversion of graphics to graphics2d
GeneralPath gp1 = new GeneralPath();
GeneralPath gp2 = new GeneralPath();
Graphics2D g2d = (Graphics2D) g;
Point2D.Double gpoint= new Point2D.Double(0,250);
//initial move tos
gp1.moveTo((float)gpoint.x,(float)gpoint.y);
gp2.moveTo((float)gpoint.x,(float)gpoint.y);
g2d.setColor(Color.red);
for (double i = 1;i<250;i++){
gpoint.setLocation(2*i,250+ (100*Math.sin(i/4)));
gp1.lineTo((float)gpoint.x,(float)gpoint.y);
g2d.drawRect((int) gpoint.x,(int)gpoint.y, 1,1);
gpoint.setLocation(2*i,250+ (200*Math.sin(i/8)));
gp2.lineTo((float)gpoint.x,(float)gpoint.y);
g2d.drawRect((int) gpoint.x,(int)gpoint.y, 1,1);
}
g2d.setColor(Color.blue);
g2d.draw(gp1);
g2d.draw(gp2);
}
}
}
- duplicates
-
JDK-4182445 RFE: java printing API does not compress image rendering
-
- Resolved
-