01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.crm.report.tests;
15:
16: import org.jetbrains.annotations.NotNull;
17: import org.jfree.report.ImageElement;
18: import org.jfree.report.JFreeReport;
19: import org.jfree.report.JFreeReportBoot;
20: import org.jfree.report.TableDataFactory;
21: import org.jfree.report.elementfactory.ImageFieldElementFactory;
22: import org.jfree.report.modules.gui.base.PreviewFrame;
23: import org.pentaho.reportdesigner.crm.report.ReportDialogConstants;
24:
25: import javax.swing.table.DefaultTableModel;
26: import java.awt.*;
27: import java.awt.image.BufferedImage;
28: import java.util.Vector;
29:
30: /**
31: * User: Martin
32: * Date: 08.03.2006
33: * Time: 21:25:16
34: */
35: @SuppressWarnings({"ALL"})
36: public class ImageFieldTest {
37: public static void main(@NotNull
38: String[] args) {
39: Vector columnNames = new Vector();
40: columnNames.add("DYNAMIC_IMAGE");
41: DefaultTableModel reportTableModel = new DefaultTableModel(
42: columnNames, 5) {
43: public Class<?> getColumnClass(int columnIndex) {
44: return Image.class;
45: }
46:
47: public Object getValueAt(int row, int column) {
48: BufferedImage bi = new BufferedImage(50, 30,
49: BufferedImage.TYPE_INT_ARGB);
50: Graphics graphics = bi.getGraphics();
51: graphics.setColor(Color.GREEN);
52: graphics.fillRect(0, 0, 50, 30);
53: graphics.setColor(Color.BLACK);
54: graphics.drawString("(" + row + ", " + column + ")",
55: 10, 15);
56: return bi;
57: }
58: };
59:
60: JFreeReport report = new JFreeReport();
61:
62: ImageElement imageElement = ImageFieldElementFactory
63: .createImageDataRowElement("imageField", new Rectangle(
64: 0, 0, 50, 30), "DYNAMIC_IMAGE", true, false);
65:
66: report.getItemBand().addElement(imageElement);
67: report.getItemBand().setMinimumSize(new Dimension(0, 50));
68:
69: report.setDataFactory(new TableDataFactory(
70: ReportDialogConstants.DEFAULT_DATA_FACTORY,
71: reportTableModel));
72:
73: JFreeReportBoot.getInstance().start();
74:
75: PreviewFrame preview = new PreviewFrame(report);
76: preview.pack();
77: preview.setVisible(true);
78: }
79: }
|