[Date Prev][Date Next][Index][Thread]
[SGT Mail Archive]
[SGT Main Page]
Problems with printing - shadow present
Dear All,
I developed an Applet / Application (it has both init() and main() methods) for plotting oceanographic data. I used SGT (
http://www.epic.noaa.gov/java/sgt/) toolkit for plot generation.
Everything works fine until when I print the plots. After generating the print using the below procedure an 'echo' is generated. This causes any movement of the individual components (layers) to leave a shadow on the original position. Guess the screen shots available at
http://www.dezo.org/java_printing/ will explain the problem better:
- print_problem-01.jpg is the original view showing some components were already moved - see the line keys (legend) at the bottom - the keys were moved a bit to the right. There is no shadow left at the original position.
- print_problem-02.jpg shows the view immediatelly after the graphic is printed. Here a shadow is already visible.
- print_problem-03.jpg shows what happens if a component is moved after the graphic is printed - see the line keys at the bottom or the image at the top.
I'm using the following Print button action for printing:
----
public void PrintGraph() throws Exception {
mMbpGraph = mGuiGraphView.getGraphPane();
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setCopies(1);
Date now = new Date();
Format formatter;
formatter = new SimpleDateFormat("yyyyMMdd_HHmm");
String jobName = mDp.getGraphName() + "-" + formatter.format(now);
printJob.setJobName(jobName);
try {
if ( printJob.printDialog() ) {
mGuiGraphView.setBatch(false);
PageFormat pf = printJob.defaultPage();
printJob.pageDialog(pf);
pf = printJob.validatePage(pf);
Printable adapter = new Printable() {
public int print(Graphics g, PageFormat pf, int page) {
if (page > 0) return Printable.NO_SUCH_PAGE;
Graphics2D g2 = (Graphics2D) g;
int width = mMbpGraph.getWidth();
double scale = pf.getImageableWidth() / width;
int tx = (int) pf.getImageableX();
int ty = (int) pf.getImageableY();
g2.translate(tx,ty);
g2.scale(scale,scale);
mMbpGraph.draw(g2);
return Printable.PAGE_EXISTS;
}
};
printJob.setPrintable(adapter, pf);
printJob.print();
} // if ( printJob.printDialog() )
} catch (PrinterException e) {
mLogger.log(Level.SEVERE, e.getMessage(), e);
}
mMainContainer.setVisible(false);
mMainContainer.remove(mGuiGraphView);
mGuiGraphView.setBatch(false);
// -- This is a workaround that solves the problem, but it is NOT the solution - see
// below --
/* mGuiGraphView.removeAll();
* mGuiGraphView = new GuiGraphView(this, mDp, mLang.toUpperCase());
*/
mMainContainer.add(mGuiGraphView);
mMainContainer.setVisible(true);
return;
} // PrintGraph()
----
The commented out workaround solves the problem but it is not the solution as it causes all the modification of the plot as e.g. line attributes editing, movements, etc. to be lost.
The live applet implementing the workaround can be seen at
http://buoy.mbss.org/ismo/data/ << see only the plots (not counting the 'Wind live data' and the 'Tidal prediction in the port of Koper').
Thanks and best regards,
Damir Dezeljin
Privacy Notice,
External Links Disclaimer.