0001: /*
0002: * ============================================================================
0003: * GNU Lesser General Public License
0004: * ============================================================================
0005: *
0006: * JasperReports - Free Java report-generating library.
0007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
0008: *
0009: * This library is free software; you can redistribute it and/or
0010: * modify it under the terms of the GNU Lesser General Public
0011: * License as published by the Free Software Foundation; either
0012: * version 2.1 of the License, or (at your option) any later version.
0013: *
0014: * This library is distributed in the hope that it will be useful,
0015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0017: * Lesser General Public License for more details.
0018: *
0019: * You should have received a copy of the GNU Lesser General Public
0020: * License along with this library; if not, write to the Free Software
0021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
0022: *
0023: * JasperSoft Corporation
0024: * 303 Second Street, Suite 450 North
0025: * San Francisco, CA 94107
0026: * http://www.jaspersoft.com
0027: */
0028:
0029: /*
0030: * Contributors:
0031: * Ryan Johnson - delscovich@users.sourceforge.net
0032: * Carlton Moore - cmoore79@users.sourceforge.net
0033: * Petr Michalek - pmichalek@users.sourceforge.net
0034: */
0035: package net.sf.jasperreports.view;
0036:
0037: import java.awt.Component;
0038: import java.awt.Container;
0039: import java.awt.Cursor;
0040: import java.awt.Dimension;
0041: import java.awt.Graphics;
0042: import java.awt.Graphics2D;
0043: import java.awt.Image;
0044: import java.awt.Point;
0045: import java.awt.Rectangle;
0046: import java.awt.Toolkit;
0047: import java.awt.event.KeyEvent;
0048: import java.awt.event.KeyListener;
0049: import java.awt.event.MouseEvent;
0050: import java.awt.event.MouseListener;
0051: import java.awt.event.MouseMotionListener;
0052: import java.io.File;
0053: import java.io.InputStream;
0054: import java.lang.reflect.Method;
0055: import java.text.DecimalFormat;
0056: import java.text.MessageFormat;
0057: import java.text.ParseException;
0058: import java.util.ArrayList;
0059: import java.util.Arrays;
0060: import java.util.HashMap;
0061: import java.util.Iterator;
0062: import java.util.List;
0063: import java.util.Locale;
0064: import java.util.Map;
0065: import java.util.ResourceBundle;
0066:
0067: import javax.swing.DefaultComboBoxModel;
0068: import javax.swing.ImageIcon;
0069: import javax.swing.JFileChooser;
0070: import javax.swing.JLabel;
0071: import javax.swing.JOptionPane;
0072: import javax.swing.JPanel;
0073: import javax.swing.JViewport;
0074: import javax.swing.filechooser.FileFilter;
0075:
0076: import net.sf.jasperreports.engine.JRException;
0077: import net.sf.jasperreports.engine.JRExporterParameter;
0078: import net.sf.jasperreports.engine.JRHyperlink;
0079: import net.sf.jasperreports.engine.JRImageMapRenderer;
0080: import net.sf.jasperreports.engine.JRPrintAnchorIndex;
0081: import net.sf.jasperreports.engine.JRPrintElement;
0082: import net.sf.jasperreports.engine.JRPrintFrame;
0083: import net.sf.jasperreports.engine.JRPrintHyperlink;
0084: import net.sf.jasperreports.engine.JRPrintImage;
0085: import net.sf.jasperreports.engine.JRPrintImageAreaHyperlink;
0086: import net.sf.jasperreports.engine.JRPrintPage;
0087: import net.sf.jasperreports.engine.JRRenderable;
0088: import net.sf.jasperreports.engine.JRRuntimeException;
0089: import net.sf.jasperreports.engine.JasperPrint;
0090: import net.sf.jasperreports.engine.JasperPrintManager;
0091: import net.sf.jasperreports.engine.export.JRGraphics2DExporter;
0092: import net.sf.jasperreports.engine.export.JRGraphics2DExporterParameter;
0093: import net.sf.jasperreports.engine.print.JRPrinterAWT;
0094: import net.sf.jasperreports.engine.util.JRClassLoader;
0095: import net.sf.jasperreports.engine.util.JRLoader;
0096: import net.sf.jasperreports.engine.util.JRProperties;
0097: import net.sf.jasperreports.engine.xml.JRPrintXmlLoader;
0098: import net.sf.jasperreports.view.save.JRPrintSaveContributor;
0099:
0100: /**
0101: * @author Teodor Danciu (teodord@users.sourceforge.net)
0102: * @version $Id: JRViewer.java 1797 2007-07-30 09:38:35Z teodord $
0103: */
0104: public class JRViewer extends javax.swing.JPanel implements
0105: JRHyperlinkListener {
0106:
0107: /**
0108: * Maximum size (in pixels) of a buffered image that would be used by {@link JRViewer JRViewer} to render a report page.
0109: * <p>
0110: * If rendering a report page would require an image larger than this threshold
0111: * (i.e. image width x image height > maximum size), the report page will be rendered directly on the viewer component.
0112: * </p>
0113: * <p>
0114: * If this property is zero or negative, buffered images will never be user to render a report page.
0115: * By default, this property is set to 0.
0116: * </p>
0117: */
0118: public static final String VIEWER_RENDER_BUFFER_MAX_SIZE = JRProperties.PROPERTY_PREFIX
0119: + "viewer.render.buffer.max.size";
0120:
0121: /**
0122: *
0123: */
0124: protected static final int TYPE_FILE_NAME = 1;
0125: protected static final int TYPE_INPUT_STREAM = 2;
0126: protected static final int TYPE_OBJECT = 3;
0127:
0128: /**
0129: * The DPI of the generated report.
0130: */
0131: public static final int REPORT_RESOLUTION = 72;
0132:
0133: protected float MIN_ZOOM = 0.5f;
0134: protected float MAX_ZOOM = 10f;
0135: protected int zooms[] = { 50, 75, 100, 125, 150, 175, 200, 250,
0136: 400, 800 };
0137: protected int defaultZoomIndex = 2;
0138:
0139: protected int type = TYPE_FILE_NAME;
0140: protected boolean isXML = false;
0141: protected String reportFileName = null;
0142: JasperPrint jasperPrint = null;
0143: private int pageIndex = 0;
0144: protected float zoom = 0f;
0145:
0146: private JRGraphics2DExporter exporter = null;
0147:
0148: /**
0149: * the screen resolution.
0150: */
0151: private int screenResolution = REPORT_RESOLUTION;
0152:
0153: /**
0154: * the zoom ration adjusted to the screen resolution.
0155: */
0156: protected float realZoom = 0f;
0157:
0158: private DecimalFormat zoomDecimalFormat = new DecimalFormat("#.##");
0159: private ResourceBundle resourceBundle = null;
0160:
0161: private int downX = 0;
0162: private int downY = 0;
0163:
0164: private java.util.List hyperlinkListeners = new ArrayList();
0165: private Map linksMap = new HashMap();
0166: private MouseListener mouseListener = new java.awt.event.MouseAdapter() {
0167: public void mouseClicked(java.awt.event.MouseEvent evt) {
0168: hyperlinkClicked(evt);
0169: }
0170: };
0171:
0172: private KeyListener keyNavigationListener = new KeyListener() {
0173: public void keyTyped(KeyEvent evt) {
0174: }
0175:
0176: public void keyPressed(KeyEvent evt) {
0177: keyNavigate(evt);
0178: }
0179:
0180: public void keyReleased(KeyEvent evt) {
0181: }
0182: };
0183:
0184: private java.util.List saveContributors = new ArrayList();
0185:
0186: /** Creates new form JRViewer */
0187: public JRViewer(String fileName, boolean isXML) throws JRException {
0188: this (fileName, isXML, null);
0189: }
0190:
0191: /** Creates new form JRViewer */
0192: public JRViewer(InputStream is, boolean isXML) throws JRException {
0193: this (is, isXML, null);
0194: }
0195:
0196: /** Creates new form JRViewer */
0197: public JRViewer(JasperPrint jrPrint) {
0198: this (jrPrint, null);
0199: }
0200:
0201: /** Creates new form JRViewer */
0202: public JRViewer(String fileName, boolean isXML, Locale locale)
0203: throws JRException {
0204: this (fileName, isXML, locale, null);
0205: }
0206:
0207: /** Creates new form JRViewer */
0208: public JRViewer(InputStream is, boolean isXML, Locale locale)
0209: throws JRException {
0210: this (is, isXML, locale, null);
0211: }
0212:
0213: /** Creates new form JRViewer */
0214: public JRViewer(JasperPrint jrPrint, Locale locale) {
0215: this (jrPrint, locale, null);
0216: }
0217:
0218: /** Creates new form JRViewer */
0219: public JRViewer(String fileName, boolean isXML, Locale locale,
0220: ResourceBundle resBundle) throws JRException {
0221: initResources(locale, resBundle);
0222:
0223: setScreenDetails();
0224:
0225: setZooms();
0226:
0227: initComponents();
0228:
0229: loadReport(fileName, isXML);
0230:
0231: cmbZoom.setSelectedIndex(defaultZoomIndex);
0232:
0233: initSaveContributors();
0234:
0235: addHyperlinkListener(this );
0236: }
0237:
0238: /** Creates new form JRViewer */
0239: public JRViewer(InputStream is, boolean isXML, Locale locale,
0240: ResourceBundle resBundle) throws JRException {
0241: initResources(locale, resBundle);
0242:
0243: setScreenDetails();
0244:
0245: setZooms();
0246:
0247: initComponents();
0248:
0249: loadReport(is, isXML);
0250:
0251: cmbZoom.setSelectedIndex(defaultZoomIndex);
0252:
0253: initSaveContributors();
0254:
0255: addHyperlinkListener(this );
0256: }
0257:
0258: /** Creates new form JRViewer */
0259: public JRViewer(JasperPrint jrPrint, Locale locale,
0260: ResourceBundle resBundle) {
0261: initResources(locale, resBundle);
0262:
0263: setScreenDetails();
0264:
0265: setZooms();
0266:
0267: initComponents();
0268:
0269: loadReport(jrPrint);
0270:
0271: cmbZoom.setSelectedIndex(defaultZoomIndex);
0272:
0273: initSaveContributors();
0274:
0275: addHyperlinkListener(this );
0276: }
0277:
0278: private void setScreenDetails() {
0279: screenResolution = Toolkit.getDefaultToolkit()
0280: .getScreenResolution();
0281: }
0282:
0283: /**
0284: *
0285: */
0286: public void clear() {
0287: emptyContainer(this );
0288: jasperPrint = null;
0289: }
0290:
0291: /**
0292: *
0293: */
0294: protected void setZooms() {
0295: }
0296:
0297: /**
0298: *
0299: */
0300: public void addSaveContributor(JRSaveContributor contributor) {
0301: saveContributors.add(contributor);
0302: }
0303:
0304: /**
0305: *
0306: */
0307: public void removeSaveContributor(JRSaveContributor contributor) {
0308: saveContributors.remove(contributor);
0309: }
0310:
0311: /**
0312: *
0313: */
0314: public JRSaveContributor[] getSaveContributors() {
0315: return (JRSaveContributor[]) saveContributors
0316: .toArray(new JRSaveContributor[saveContributors.size()]);
0317: }
0318:
0319: /**
0320: *
0321: */
0322: public void addHyperlinkListener(JRHyperlinkListener listener) {
0323: hyperlinkListeners.add(listener);
0324: }
0325:
0326: /**
0327: *
0328: */
0329: public void removeHyperlinkListener(JRHyperlinkListener listener) {
0330: hyperlinkListeners.remove(listener);
0331: }
0332:
0333: /**
0334: *
0335: */
0336: public JRHyperlinkListener[] getHyperlinkListeners() {
0337: return (JRHyperlinkListener[]) hyperlinkListeners
0338: .toArray(new JRHyperlinkListener[hyperlinkListeners
0339: .size()]);
0340: }
0341:
0342: /**
0343: *
0344: */
0345: protected void initResources(Locale locale, ResourceBundle resBundle) {
0346: if (locale != null)
0347: setLocale(locale);
0348: else
0349: setLocale(Locale.getDefault());
0350:
0351: if (resBundle == null) {
0352: this .resourceBundle = ResourceBundle.getBundle(
0353: "net/sf/jasperreports/view/viewer", getLocale());
0354: } else {
0355: this .resourceBundle = resBundle;
0356: }
0357: }
0358:
0359: /**
0360: *
0361: */
0362: protected String getBundleString(String key) {
0363: return resourceBundle.getString(key);
0364: }
0365:
0366: /**
0367: *
0368: */
0369: protected void initSaveContributors() {
0370: final String[] DEFAULT_CONTRIBUTORS = {
0371: "net.sf.jasperreports.view.save.JRPrintSaveContributor",
0372: "net.sf.jasperreports.view.save.JRPdfSaveContributor",
0373: "net.sf.jasperreports.view.save.JRRtfSaveContributor",
0374: "net.sf.jasperreports.view.save.JROdtSaveContributor",
0375: "net.sf.jasperreports.view.save.JRHtmlSaveContributor",
0376: "net.sf.jasperreports.view.save.JRSingleSheetXlsSaveContributor",
0377: "net.sf.jasperreports.view.save.JRMultipleSheetsXlsSaveContributor",
0378: "net.sf.jasperreports.view.save.JRCsvSaveContributor",
0379: "net.sf.jasperreports.view.save.JRXmlSaveContributor",
0380: "net.sf.jasperreports.view.save.JREmbeddedImagesXmlSaveContributor" };
0381:
0382: for (int i = 0; i < DEFAULT_CONTRIBUTORS.length; i++) {
0383: try {
0384: Class saveContribClass = JRClassLoader
0385: .loadClassForName(DEFAULT_CONTRIBUTORS[i]);
0386: Method method = saveContribClass.getMethod(
0387: "getInstance", (Class[]) null);
0388: JRSaveContributor saveContrib = (JRSaveContributor) method
0389: .invoke(null, (Object[]) null);
0390: saveContributors.add(saveContrib);
0391: } catch (Exception e) {
0392: }
0393: }
0394: }
0395:
0396: /**
0397: *
0398: */
0399: public void gotoHyperlink(JRPrintHyperlink hyperlink) {
0400: switch (hyperlink.getHyperlinkType()) {
0401: case JRHyperlink.HYPERLINK_TYPE_REFERENCE: {
0402: if (isOnlyHyperlinkListener()) {
0403: System.out.println("Hyperlink reference : "
0404: + hyperlink.getHyperlinkReference());
0405: System.out
0406: .println("Implement your own JRHyperlinkListener to manage this type of event.");
0407: }
0408: break;
0409: }
0410: case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: {
0411: if (hyperlink.getHyperlinkAnchor() != null) {
0412: Map anchorIndexes = jasperPrint.getAnchorIndexes();
0413: JRPrintAnchorIndex anchorIndex = (JRPrintAnchorIndex) anchorIndexes
0414: .get(hyperlink.getHyperlinkAnchor());
0415: if (anchorIndex.getPageIndex() != pageIndex) {
0416: setPageIndex(anchorIndex.getPageIndex());
0417: refreshPage();
0418: }
0419: Container container = pnlInScroll.getParent();
0420: if (container instanceof JViewport) {
0421: JViewport viewport = (JViewport) container;
0422:
0423: int newX = (int) (anchorIndex.getElementAbsoluteX() * realZoom);
0424: int newY = (int) (anchorIndex.getElementAbsoluteY() * realZoom);
0425:
0426: int maxX = pnlInScroll.getWidth()
0427: - viewport.getWidth();
0428: int maxY = pnlInScroll.getHeight()
0429: - viewport.getHeight();
0430:
0431: if (newX < 0) {
0432: newX = 0;
0433: }
0434: if (newX > maxX) {
0435: newX = maxX;
0436: }
0437: if (newY < 0) {
0438: newY = 0;
0439: }
0440: if (newY > maxY) {
0441: newY = maxY;
0442: }
0443:
0444: viewport.setViewPosition(new Point(newX, newY));
0445: }
0446: }
0447:
0448: break;
0449: }
0450: case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: {
0451: int page = pageIndex + 1;
0452: if (hyperlink.getHyperlinkPage() != null) {
0453: page = hyperlink.getHyperlinkPage().intValue();
0454: }
0455:
0456: if (page >= 1 && page <= jasperPrint.getPages().size()
0457: && page != pageIndex + 1) {
0458: setPageIndex(page - 1);
0459: refreshPage();
0460: Container container = pnlInScroll.getParent();
0461: if (container instanceof JViewport) {
0462: JViewport viewport = (JViewport) container;
0463: viewport.setViewPosition(new Point(0, 0));
0464: }
0465: }
0466:
0467: break;
0468: }
0469: case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: {
0470: if (isOnlyHyperlinkListener()) {
0471: System.out.println("Hyperlink reference : "
0472: + hyperlink.getHyperlinkReference());
0473: System.out.println("Hyperlink anchor : "
0474: + hyperlink.getHyperlinkAnchor());
0475: System.out
0476: .println("Implement your own JRHyperlinkListener to manage this type of event.");
0477: }
0478: break;
0479: }
0480: case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: {
0481: if (isOnlyHyperlinkListener()) {
0482: System.out.println("Hyperlink reference : "
0483: + hyperlink.getHyperlinkReference());
0484: System.out.println("Hyperlink page : "
0485: + hyperlink.getHyperlinkPage());
0486: System.out
0487: .println("Implement your own JRHyperlinkListener to manage this type of event.");
0488: }
0489: break;
0490: }
0491: case JRHyperlink.HYPERLINK_TYPE_CUSTOM: {
0492: if (isOnlyHyperlinkListener()) {
0493: System.out.println("Hyperlink of type "
0494: + hyperlink.getLinkType());
0495: System.out
0496: .println("Implement your own JRHyperlinkListener to manage this type of event.");
0497: }
0498: break;
0499: }
0500: case JRHyperlink.HYPERLINK_TYPE_NONE:
0501: default: {
0502: break;
0503: }
0504: }
0505: }
0506:
0507: protected boolean isOnlyHyperlinkListener() {
0508: int listenerCount;
0509: if (hyperlinkListeners == null) {
0510: listenerCount = 0;
0511: } else {
0512: listenerCount = hyperlinkListeners.size();
0513: if (hyperlinkListeners.contains(this )) {
0514: --listenerCount;
0515: }
0516: }
0517: return listenerCount == 0;
0518: }
0519:
0520: /** This method is called from within the constructor to
0521: * initialize the form.
0522: * WARNING: Do NOT modify this code. The content of this method is
0523: * always regenerated by the Form Editor.
0524: */
0525: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
0526: private void initComponents() {
0527: java.awt.GridBagConstraints gridBagConstraints;
0528:
0529: tlbToolBar = new javax.swing.JPanel();
0530: btnSave = new javax.swing.JButton();
0531: btnPrint = new javax.swing.JButton();
0532: btnReload = new javax.swing.JButton();
0533: pnlSep01 = new javax.swing.JPanel();
0534: btnFirst = new javax.swing.JButton();
0535: btnPrevious = new javax.swing.JButton();
0536: btnNext = new javax.swing.JButton();
0537: btnLast = new javax.swing.JButton();
0538: txtGoTo = new javax.swing.JTextField();
0539: pnlSep02 = new javax.swing.JPanel();
0540: btnActualSize = new javax.swing.JToggleButton();
0541: btnFitPage = new javax.swing.JToggleButton();
0542: btnFitWidth = new javax.swing.JToggleButton();
0543: pnlSep03 = new javax.swing.JPanel();
0544: btnZoomIn = new javax.swing.JButton();
0545: btnZoomOut = new javax.swing.JButton();
0546: cmbZoom = new javax.swing.JComboBox();
0547: DefaultComboBoxModel model = new DefaultComboBoxModel();
0548: for (int i = 0; i < zooms.length; i++) {
0549: model.addElement("" + zooms[i] + "%");
0550: }
0551: cmbZoom.setModel(model);
0552:
0553: pnlMain = new javax.swing.JPanel();
0554: scrollPane = new javax.swing.JScrollPane();
0555: scrollPane.getHorizontalScrollBar().setUnitIncrement(5);
0556: scrollPane.getVerticalScrollBar().setUnitIncrement(5);
0557:
0558: pnlInScroll = new javax.swing.JPanel();
0559: pnlPage = new javax.swing.JPanel();
0560: jPanel4 = new javax.swing.JPanel();
0561: pnlLinks = new javax.swing.JPanel();
0562: jPanel5 = new javax.swing.JPanel();
0563: jPanel6 = new javax.swing.JPanel();
0564: jPanel7 = new javax.swing.JPanel();
0565: jPanel8 = new javax.swing.JPanel();
0566: jLabel1 = new javax.swing.JLabel();
0567: jPanel9 = new javax.swing.JPanel();
0568: lblPage = new PageRenderer(this );
0569: pnlStatus = new javax.swing.JPanel();
0570: lblStatus = new javax.swing.JLabel();
0571:
0572: setLayout(new java.awt.BorderLayout());
0573:
0574: setMinimumSize(new java.awt.Dimension(450, 150));
0575: setPreferredSize(new java.awt.Dimension(450, 150));
0576: tlbToolBar.setLayout(new java.awt.FlowLayout(
0577: java.awt.FlowLayout.LEFT, 0, 2));
0578:
0579: btnSave.setIcon(new javax.swing.ImageIcon(getClass()
0580: .getResource(
0581: "/net/sf/jasperreports/view/images/save.GIF")));
0582: btnSave.setToolTipText(getBundleString("save"));
0583: btnSave.setMargin(new java.awt.Insets(2, 2, 2, 2));
0584: btnSave.setMaximumSize(new java.awt.Dimension(23, 23));
0585: btnSave.setMinimumSize(new java.awt.Dimension(23, 23));
0586: btnSave.setPreferredSize(new java.awt.Dimension(23, 23));
0587: btnSave.addActionListener(new java.awt.event.ActionListener() {
0588: public void actionPerformed(java.awt.event.ActionEvent evt) {
0589: btnSaveActionPerformed(evt);
0590: }
0591: });
0592: btnSave.addKeyListener(keyNavigationListener);
0593: tlbToolBar.add(btnSave);
0594:
0595: btnPrint
0596: .setIcon(new javax.swing.ImageIcon(
0597: getClass()
0598: .getResource(
0599: "/net/sf/jasperreports/view/images/print.GIF")));
0600: btnPrint.setToolTipText(getBundleString("print"));
0601: btnPrint.setMargin(new java.awt.Insets(2, 2, 2, 2));
0602: btnPrint.setMaximumSize(new java.awt.Dimension(23, 23));
0603: btnPrint.setMinimumSize(new java.awt.Dimension(23, 23));
0604: btnPrint.setPreferredSize(new java.awt.Dimension(23, 23));
0605: btnPrint.addActionListener(new java.awt.event.ActionListener() {
0606: public void actionPerformed(java.awt.event.ActionEvent evt) {
0607: btnPrintActionPerformed(evt);
0608: }
0609: });
0610: btnPrint.addKeyListener(keyNavigationListener);
0611: tlbToolBar.add(btnPrint);
0612:
0613: btnReload
0614: .setIcon(new javax.swing.ImageIcon(
0615: getClass()
0616: .getResource(
0617: "/net/sf/jasperreports/view/images/reload.GIF")));
0618: btnReload.setToolTipText(getBundleString("reload"));
0619: btnReload.setMargin(new java.awt.Insets(2, 2, 2, 2));
0620: btnReload.setMaximumSize(new java.awt.Dimension(23, 23));
0621: btnReload.setMinimumSize(new java.awt.Dimension(23, 23));
0622: btnReload.setPreferredSize(new java.awt.Dimension(23, 23));
0623: btnReload
0624: .addActionListener(new java.awt.event.ActionListener() {
0625: public void actionPerformed(
0626: java.awt.event.ActionEvent evt) {
0627: btnReloadActionPerformed(evt);
0628: }
0629: });
0630: btnReload.addKeyListener(keyNavigationListener);
0631: tlbToolBar.add(btnReload);
0632:
0633: pnlSep01.setMaximumSize(new java.awt.Dimension(10, 10));
0634: tlbToolBar.add(pnlSep01);
0635:
0636: btnFirst
0637: .setIcon(new javax.swing.ImageIcon(
0638: getClass()
0639: .getResource(
0640: "/net/sf/jasperreports/view/images/first.GIF")));
0641: btnFirst.setToolTipText(getBundleString("first.page"));
0642: btnFirst.setMargin(new java.awt.Insets(2, 2, 2, 2));
0643: btnFirst.setMaximumSize(new java.awt.Dimension(23, 23));
0644: btnFirst.setMinimumSize(new java.awt.Dimension(23, 23));
0645: btnFirst.setPreferredSize(new java.awt.Dimension(23, 23));
0646: btnFirst.addActionListener(new java.awt.event.ActionListener() {
0647: public void actionPerformed(java.awt.event.ActionEvent evt) {
0648: btnFirstActionPerformed(evt);
0649: }
0650: });
0651: btnFirst.addKeyListener(keyNavigationListener);
0652: tlbToolBar.add(btnFirst);
0653:
0654: btnPrevious
0655: .setIcon(new javax.swing.ImageIcon(
0656: getClass()
0657: .getResource(
0658: "/net/sf/jasperreports/view/images/previous.GIF")));
0659: btnPrevious.setToolTipText(getBundleString("previous.page"));
0660: btnPrevious.setMargin(new java.awt.Insets(2, 2, 2, 2));
0661: btnPrevious.setMaximumSize(new java.awt.Dimension(23, 23));
0662: btnPrevious.setMinimumSize(new java.awt.Dimension(23, 23));
0663: btnPrevious.setPreferredSize(new java.awt.Dimension(23, 23));
0664: btnPrevious
0665: .addActionListener(new java.awt.event.ActionListener() {
0666: public void actionPerformed(
0667: java.awt.event.ActionEvent evt) {
0668: btnPreviousActionPerformed(evt);
0669: }
0670: });
0671: btnPrevious.addKeyListener(keyNavigationListener);
0672: tlbToolBar.add(btnPrevious);
0673:
0674: btnNext.setIcon(new javax.swing.ImageIcon(getClass()
0675: .getResource(
0676: "/net/sf/jasperreports/view/images/next.GIF")));
0677: btnNext.setToolTipText(getBundleString("next.page"));
0678: btnNext.setMargin(new java.awt.Insets(2, 2, 2, 2));
0679: btnNext.setMaximumSize(new java.awt.Dimension(23, 23));
0680: btnNext.setMinimumSize(new java.awt.Dimension(23, 23));
0681: btnNext.setPreferredSize(new java.awt.Dimension(23, 23));
0682: btnNext.addActionListener(new java.awt.event.ActionListener() {
0683: public void actionPerformed(java.awt.event.ActionEvent evt) {
0684: btnNextActionPerformed(evt);
0685: }
0686: });
0687: btnNext.addKeyListener(keyNavigationListener);
0688: tlbToolBar.add(btnNext);
0689:
0690: btnLast.setIcon(new javax.swing.ImageIcon(getClass()
0691: .getResource(
0692: "/net/sf/jasperreports/view/images/last.GIF")));
0693: btnLast.setToolTipText(getBundleString("last.page"));
0694: btnLast.setMargin(new java.awt.Insets(2, 2, 2, 2));
0695: btnLast.setMaximumSize(new java.awt.Dimension(23, 23));
0696: btnLast.setMinimumSize(new java.awt.Dimension(23, 23));
0697: btnLast.setPreferredSize(new java.awt.Dimension(23, 23));
0698: btnLast.addActionListener(new java.awt.event.ActionListener() {
0699: public void actionPerformed(java.awt.event.ActionEvent evt) {
0700: btnLastActionPerformed(evt);
0701: }
0702: });
0703: btnLast.addKeyListener(keyNavigationListener);
0704: tlbToolBar.add(btnLast);
0705:
0706: txtGoTo.setToolTipText(getBundleString("go.to.page"));
0707: txtGoTo.setMaximumSize(new java.awt.Dimension(40, 23));
0708: txtGoTo.setMinimumSize(new java.awt.Dimension(40, 23));
0709: txtGoTo.setPreferredSize(new java.awt.Dimension(40, 23));
0710: txtGoTo.addActionListener(new java.awt.event.ActionListener() {
0711: public void actionPerformed(java.awt.event.ActionEvent evt) {
0712: txtGoToActionPerformed(evt);
0713: }
0714: });
0715: txtGoTo.addKeyListener(keyNavigationListener);
0716: tlbToolBar.add(txtGoTo);
0717:
0718: pnlSep02.setMaximumSize(new java.awt.Dimension(10, 10));
0719: tlbToolBar.add(pnlSep02);
0720:
0721: btnActualSize
0722: .setIcon(new javax.swing.ImageIcon(
0723: getClass()
0724: .getResource(
0725: "/net/sf/jasperreports/view/images/actualsize.GIF")));
0726: btnActualSize.setToolTipText(getBundleString("actual.size"));
0727: btnActualSize.setMargin(new java.awt.Insets(2, 2, 2, 2));
0728: btnActualSize.setMaximumSize(new java.awt.Dimension(23, 23));
0729: btnActualSize.setMinimumSize(new java.awt.Dimension(23, 23));
0730: btnActualSize.setPreferredSize(new java.awt.Dimension(23, 23));
0731: btnActualSize
0732: .addActionListener(new java.awt.event.ActionListener() {
0733: public void actionPerformed(
0734: java.awt.event.ActionEvent evt) {
0735: btnActualSizeActionPerformed(evt);
0736: }
0737: });
0738: btnActualSize.addKeyListener(keyNavigationListener);
0739: tlbToolBar.add(btnActualSize);
0740:
0741: btnFitPage
0742: .setIcon(new javax.swing.ImageIcon(
0743: getClass()
0744: .getResource(
0745: "/net/sf/jasperreports/view/images/fitpage.GIF")));
0746: btnFitPage.setToolTipText(getBundleString("fit.page"));
0747: btnFitPage.setMargin(new java.awt.Insets(2, 2, 2, 2));
0748: btnFitPage.setMaximumSize(new java.awt.Dimension(23, 23));
0749: btnFitPage.setMinimumSize(new java.awt.Dimension(23, 23));
0750: btnFitPage.setPreferredSize(new java.awt.Dimension(23, 23));
0751: btnFitPage
0752: .addActionListener(new java.awt.event.ActionListener() {
0753: public void actionPerformed(
0754: java.awt.event.ActionEvent evt) {
0755: btnFitPageActionPerformed(evt);
0756: }
0757: });
0758: btnFitPage.addKeyListener(keyNavigationListener);
0759: tlbToolBar.add(btnFitPage);
0760:
0761: btnFitWidth
0762: .setIcon(new javax.swing.ImageIcon(
0763: getClass()
0764: .getResource(
0765: "/net/sf/jasperreports/view/images/fitwidth.GIF")));
0766: btnFitWidth.setToolTipText(getBundleString("fit.width"));
0767: btnFitWidth.setMargin(new java.awt.Insets(2, 2, 2, 2));
0768: btnFitWidth.setMaximumSize(new java.awt.Dimension(23, 23));
0769: btnFitWidth.setMinimumSize(new java.awt.Dimension(23, 23));
0770: btnFitWidth.setPreferredSize(new java.awt.Dimension(23, 23));
0771: btnFitWidth
0772: .addActionListener(new java.awt.event.ActionListener() {
0773: public void actionPerformed(
0774: java.awt.event.ActionEvent evt) {
0775: btnFitWidthActionPerformed(evt);
0776: }
0777: });
0778: btnFitWidth.addKeyListener(keyNavigationListener);
0779: tlbToolBar.add(btnFitWidth);
0780:
0781: pnlSep03.setMaximumSize(new java.awt.Dimension(10, 10));
0782: tlbToolBar.add(pnlSep03);
0783:
0784: btnZoomIn
0785: .setIcon(new javax.swing.ImageIcon(
0786: getClass()
0787: .getResource(
0788: "/net/sf/jasperreports/view/images/zoomin.GIF")));
0789: btnZoomIn.setToolTipText(getBundleString("zoom.in"));
0790: btnZoomIn.setMargin(new java.awt.Insets(2, 2, 2, 2));
0791: btnZoomIn.setMaximumSize(new java.awt.Dimension(23, 23));
0792: btnZoomIn.setMinimumSize(new java.awt.Dimension(23, 23));
0793: btnZoomIn.setPreferredSize(new java.awt.Dimension(23, 23));
0794: btnZoomIn
0795: .addActionListener(new java.awt.event.ActionListener() {
0796: public void actionPerformed(
0797: java.awt.event.ActionEvent evt) {
0798: btnZoomInActionPerformed(evt);
0799: }
0800: });
0801: btnZoomIn.addKeyListener(keyNavigationListener);
0802: tlbToolBar.add(btnZoomIn);
0803:
0804: btnZoomOut
0805: .setIcon(new javax.swing.ImageIcon(
0806: getClass()
0807: .getResource(
0808: "/net/sf/jasperreports/view/images/zoomout.GIF")));
0809: btnZoomOut.setToolTipText(getBundleString("zoom.out"));
0810: btnZoomOut.setMargin(new java.awt.Insets(2, 2, 2, 2));
0811: btnZoomOut.setMaximumSize(new java.awt.Dimension(23, 23));
0812: btnZoomOut.setMinimumSize(new java.awt.Dimension(23, 23));
0813: btnZoomOut.setPreferredSize(new java.awt.Dimension(23, 23));
0814: btnZoomOut
0815: .addActionListener(new java.awt.event.ActionListener() {
0816: public void actionPerformed(
0817: java.awt.event.ActionEvent evt) {
0818: btnZoomOutActionPerformed(evt);
0819: }
0820: });
0821: btnZoomOut.addKeyListener(keyNavigationListener);
0822: tlbToolBar.add(btnZoomOut);
0823:
0824: cmbZoom.setEditable(true);
0825: cmbZoom.setToolTipText(getBundleString("zoom.ratio"));
0826: cmbZoom.setMaximumSize(new java.awt.Dimension(80, 23));
0827: cmbZoom.setMinimumSize(new java.awt.Dimension(80, 23));
0828: cmbZoom.setPreferredSize(new java.awt.Dimension(80, 23));
0829: cmbZoom.addActionListener(new java.awt.event.ActionListener() {
0830: public void actionPerformed(java.awt.event.ActionEvent evt) {
0831: cmbZoomActionPerformed(evt);
0832: }
0833: });
0834: cmbZoom.addItemListener(new java.awt.event.ItemListener() {
0835: public void itemStateChanged(java.awt.event.ItemEvent evt) {
0836: cmbZoomItemStateChanged(evt);
0837: }
0838: });
0839: cmbZoom.addKeyListener(keyNavigationListener);
0840: tlbToolBar.add(cmbZoom);
0841:
0842: add(tlbToolBar, java.awt.BorderLayout.NORTH);
0843:
0844: pnlMain.setLayout(new java.awt.BorderLayout());
0845: pnlMain
0846: .addComponentListener(new java.awt.event.ComponentAdapter() {
0847: public void componentResized(
0848: java.awt.event.ComponentEvent evt) {
0849: pnlMainComponentResized(evt);
0850: }
0851: });
0852:
0853: scrollPane
0854: .setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
0855: scrollPane
0856: .setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
0857: pnlInScroll.setLayout(new java.awt.GridBagLayout());
0858:
0859: pnlPage.setLayout(new java.awt.BorderLayout());
0860: pnlPage.setMinimumSize(new java.awt.Dimension(100, 100));
0861: pnlPage.setPreferredSize(new java.awt.Dimension(100, 100));
0862:
0863: jPanel4.setLayout(new java.awt.GridBagLayout());
0864: jPanel4.setMinimumSize(new java.awt.Dimension(100, 120));
0865: jPanel4.setPreferredSize(new java.awt.Dimension(100, 120));
0866:
0867: pnlLinks.setLayout(null);
0868: pnlLinks.setMinimumSize(new java.awt.Dimension(5, 5));
0869: pnlLinks.setPreferredSize(new java.awt.Dimension(5, 5));
0870: pnlLinks.setOpaque(false);
0871: pnlLinks.addMouseListener(new java.awt.event.MouseAdapter() {
0872: public void mousePressed(java.awt.event.MouseEvent evt) {
0873: pnlLinksMousePressed(evt);
0874: }
0875:
0876: public void mouseReleased(java.awt.event.MouseEvent evt) {
0877: pnlLinksMouseReleased(evt);
0878: }
0879: });
0880: pnlLinks
0881: .addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
0882: public void mouseDragged(
0883: java.awt.event.MouseEvent evt) {
0884: pnlLinksMouseDragged(evt);
0885: }
0886: });
0887:
0888: gridBagConstraints = new java.awt.GridBagConstraints();
0889: gridBagConstraints.gridx = 0;
0890: gridBagConstraints.gridy = 0;
0891: gridBagConstraints.gridwidth = 2;
0892: gridBagConstraints.gridheight = 2;
0893: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0894: jPanel4.add(pnlLinks, gridBagConstraints);
0895:
0896: jPanel5.setBackground(java.awt.Color.gray);
0897: jPanel5.setMinimumSize(new java.awt.Dimension(5, 5));
0898: jPanel5.setPreferredSize(new java.awt.Dimension(5, 5));
0899: gridBagConstraints = new java.awt.GridBagConstraints();
0900: gridBagConstraints.gridx = 2;
0901: gridBagConstraints.gridy = 1;
0902: gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
0903: jPanel4.add(jPanel5, gridBagConstraints);
0904:
0905: jPanel6.setMinimumSize(new java.awt.Dimension(5, 5));
0906: jPanel6.setPreferredSize(new java.awt.Dimension(5, 5));
0907: gridBagConstraints = new java.awt.GridBagConstraints();
0908: gridBagConstraints.gridx = 0;
0909: gridBagConstraints.gridy = 2;
0910: jPanel4.add(jPanel6, gridBagConstraints);
0911:
0912: jPanel7.setBackground(java.awt.Color.gray);
0913: jPanel7.setMinimumSize(new java.awt.Dimension(5, 5));
0914: jPanel7.setPreferredSize(new java.awt.Dimension(5, 5));
0915: gridBagConstraints = new java.awt.GridBagConstraints();
0916: gridBagConstraints.gridx = 1;
0917: gridBagConstraints.gridy = 2;
0918: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0919: jPanel4.add(jPanel7, gridBagConstraints);
0920:
0921: jPanel8.setBackground(java.awt.Color.gray);
0922: jPanel8.setMinimumSize(new java.awt.Dimension(5, 5));
0923: jPanel8.setPreferredSize(new java.awt.Dimension(5, 5));
0924: jLabel1.setText("jLabel1");
0925: jPanel8.add(jLabel1);
0926:
0927: gridBagConstraints = new java.awt.GridBagConstraints();
0928: gridBagConstraints.gridx = 2;
0929: gridBagConstraints.gridy = 2;
0930: jPanel4.add(jPanel8, gridBagConstraints);
0931:
0932: jPanel9.setMinimumSize(new java.awt.Dimension(5, 5));
0933: jPanel9.setPreferredSize(new java.awt.Dimension(5, 5));
0934: gridBagConstraints = new java.awt.GridBagConstraints();
0935: gridBagConstraints.gridx = 2;
0936: gridBagConstraints.gridy = 0;
0937: jPanel4.add(jPanel9, gridBagConstraints);
0938:
0939: lblPage.setBackground(java.awt.Color.white);
0940: lblPage.setBorder(new javax.swing.border.LineBorder(
0941: new java.awt.Color(0, 0, 0)));
0942: lblPage.setOpaque(true);
0943: gridBagConstraints = new java.awt.GridBagConstraints();
0944: gridBagConstraints.gridx = 0;
0945: gridBagConstraints.gridy = 0;
0946: gridBagConstraints.gridwidth = 2;
0947: gridBagConstraints.gridheight = 2;
0948: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0949: gridBagConstraints.weightx = 1.0;
0950: gridBagConstraints.weighty = 1.0;
0951: jPanel4.add(lblPage, gridBagConstraints);
0952:
0953: pnlPage.add(jPanel4, java.awt.BorderLayout.CENTER);
0954:
0955: gridBagConstraints = new java.awt.GridBagConstraints();
0956: gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
0957: pnlInScroll.add(pnlPage, gridBagConstraints);
0958:
0959: scrollPane.setViewportView(pnlInScroll);
0960: pnlMain.add(scrollPane, java.awt.BorderLayout.CENTER);
0961: add(pnlMain, java.awt.BorderLayout.CENTER);
0962:
0963: pnlStatus.setLayout(new java.awt.FlowLayout(
0964: java.awt.FlowLayout.CENTER, 0, 0));
0965:
0966: lblStatus.setFont(new java.awt.Font("Dialog", 1, 10));
0967: lblStatus.setText("Page i of n");
0968: pnlStatus.add(lblStatus);
0969: add(pnlStatus, java.awt.BorderLayout.SOUTH);
0970: addKeyListener(keyNavigationListener);
0971: }
0972:
0973: // </editor-fold>//GEN-END:initComponents
0974:
0975: void txtGoToActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtGoToActionPerformed
0976: try {
0977: int pageNumber = Integer.parseInt(txtGoTo.getText());
0978: if (pageNumber != pageIndex + 1 && pageNumber > 0
0979: && pageNumber <= jasperPrint.getPages().size()) {
0980: setPageIndex(pageNumber - 1);
0981: refreshPage();
0982: }
0983: } catch (NumberFormatException e) {
0984: }
0985: }//GEN-LAST:event_txtGoToActionPerformed
0986:
0987: void cmbZoomItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbZoomItemStateChanged
0988: // Add your handling code here:
0989: btnActualSize.setSelected(false);
0990: btnFitPage.setSelected(false);
0991: btnFitWidth.setSelected(false);
0992: }//GEN-LAST:event_cmbZoomItemStateChanged
0993:
0994: void pnlMainComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_pnlMainComponentResized
0995: // Add your handling code here:
0996: if (btnFitPage.isSelected()) {
0997: fitPage();
0998: btnFitPage.setSelected(true);
0999: } else if (btnFitWidth.isSelected()) {
1000: setRealZoomRatio(((float) pnlInScroll.getVisibleRect()
1001: .getWidth() - 20f)
1002: / jasperPrint.getPageWidth());
1003: btnFitWidth.setSelected(true);
1004: }
1005:
1006: }//GEN-LAST:event_pnlMainComponentResized
1007:
1008: void btnActualSizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualSizeActionPerformed
1009: // Add your handling code here:
1010: if (btnActualSize.isSelected()) {
1011: btnFitPage.setSelected(false);
1012: btnFitWidth.setSelected(false);
1013: cmbZoom.setSelectedIndex(-1);
1014: setZoomRatio(1);
1015: btnActualSize.setSelected(true);
1016: }
1017: }//GEN-LAST:event_btnActualSizeActionPerformed
1018:
1019: void btnFitWidthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFitWidthActionPerformed
1020: // Add your handling code here:
1021: if (btnFitWidth.isSelected()) {
1022: btnActualSize.setSelected(false);
1023: btnFitPage.setSelected(false);
1024: cmbZoom.setSelectedIndex(-1);
1025: setRealZoomRatio(((float) pnlInScroll.getVisibleRect()
1026: .getWidth() - 20f)
1027: / jasperPrint.getPageWidth());
1028: btnFitWidth.setSelected(true);
1029: }
1030: }//GEN-LAST:event_btnFitWidthActionPerformed
1031:
1032: void btnFitPageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFitPageActionPerformed
1033: // Add your handling code here:
1034: if (btnFitPage.isSelected()) {
1035: btnActualSize.setSelected(false);
1036: btnFitWidth.setSelected(false);
1037: cmbZoom.setSelectedIndex(-1);
1038: fitPage();
1039: btnFitPage.setSelected(true);
1040: }
1041: }//GEN-LAST:event_btnFitPageActionPerformed
1042:
1043: void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
1044: // Add your handling code here:
1045:
1046: JFileChooser fileChooser = new JFileChooser();
1047: fileChooser.setLocale(this .getLocale());
1048: fileChooser.updateUI();
1049: for (int i = 0; i < saveContributors.size(); i++) {
1050: fileChooser
1051: .addChoosableFileFilter((JRSaveContributor) saveContributors
1052: .get(i));
1053: }
1054:
1055: if (saveContributors.size() > 0) {
1056: fileChooser
1057: .setFileFilter((JRSaveContributor) saveContributors
1058: .get(0));
1059: }
1060: int retValue = fileChooser.showSaveDialog(this );
1061: if (retValue == JFileChooser.APPROVE_OPTION) {
1062: FileFilter fileFilter = fileChooser.getFileFilter();
1063: File file = fileChooser.getSelectedFile();
1064:
1065: JRSaveContributor contributor = null;
1066:
1067: if (fileFilter instanceof JRSaveContributor) {
1068: contributor = (JRSaveContributor) fileFilter;
1069: } else {
1070: int i = 0;
1071: while (contributor == null
1072: && i < saveContributors.size()) {
1073: contributor = (JRSaveContributor) saveContributors
1074: .get(i++);
1075: if (!contributor.accept(file)) {
1076: contributor = null;
1077: }
1078: }
1079:
1080: if (contributor == null) {
1081: contributor = new JRPrintSaveContributor();
1082: }
1083: }
1084:
1085: try {
1086: contributor.save(jasperPrint, file);
1087: } catch (JRException e) {
1088: e.printStackTrace();
1089: JOptionPane.showMessageDialog(this ,
1090: getBundleString("error.saving"));
1091: }
1092: }
1093: }//GEN-LAST:event_btnSaveActionPerformed
1094:
1095: void pnlLinksMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMouseDragged
1096: // Add your handling code here:
1097:
1098: Container container = pnlInScroll.getParent();
1099: if (container instanceof JViewport) {
1100: JViewport viewport = (JViewport) container;
1101: Point point = viewport.getViewPosition();
1102: int newX = point.x - (evt.getX() - downX);
1103: int newY = point.y - (evt.getY() - downY);
1104:
1105: int maxX = pnlInScroll.getWidth() - viewport.getWidth();
1106: int maxY = pnlInScroll.getHeight() - viewport.getHeight();
1107:
1108: if (newX < 0) {
1109: newX = 0;
1110: }
1111: if (newX > maxX) {
1112: newX = maxX;
1113: }
1114: if (newY < 0) {
1115: newY = 0;
1116: }
1117: if (newY > maxY) {
1118: newY = maxY;
1119: }
1120:
1121: viewport.setViewPosition(new Point(newX, newY));
1122: }
1123: }//GEN-LAST:event_pnlLinksMouseDragged
1124:
1125: void pnlLinksMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMouseReleased
1126: // Add your handling code here:
1127: pnlLinks.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
1128: }//GEN-LAST:event_pnlLinksMouseReleased
1129:
1130: void pnlLinksMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlLinksMousePressed
1131: // Add your handling code here:
1132: pnlLinks.setCursor(new Cursor(Cursor.MOVE_CURSOR));
1133:
1134: downX = evt.getX();
1135: downY = evt.getY();
1136: }//GEN-LAST:event_pnlLinksMousePressed
1137:
1138: void btnPrintActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnPrintActionPerformed
1139: {//GEN-HEADEREND:event_btnPrintActionPerformed
1140: // Add your handling code here:
1141:
1142: Thread thread = new Thread(new Runnable() {
1143: public void run() {
1144: try {
1145: JasperPrintManager.printReport(jasperPrint, true);
1146: } catch (Exception ex) {
1147: ex.printStackTrace();
1148: JOptionPane.showMessageDialog(JRViewer.this ,
1149: getBundleString("error.printing"));
1150: }
1151: }
1152: });
1153:
1154: thread.start();
1155:
1156: }//GEN-LAST:event_btnPrintActionPerformed
1157:
1158: void btnLastActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnLastActionPerformed
1159: {//GEN-HEADEREND:event_btnLastActionPerformed
1160: // Add your handling code here:
1161: setPageIndex(jasperPrint.getPages().size() - 1);
1162: refreshPage();
1163: }//GEN-LAST:event_btnLastActionPerformed
1164:
1165: void btnNextActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnNextActionPerformed
1166: {//GEN-HEADEREND:event_btnNextActionPerformed
1167: // Add your handling code here:
1168: setPageIndex(pageIndex + 1);
1169: refreshPage();
1170: }//GEN-LAST:event_btnNextActionPerformed
1171:
1172: void btnPreviousActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnPreviousActionPerformed
1173: {//GEN-HEADEREND:event_btnPreviousActionPerformed
1174: // Add your handling code here:
1175: setPageIndex(pageIndex - 1);
1176: refreshPage();
1177: }//GEN-LAST:event_btnPreviousActionPerformed
1178:
1179: void btnFirstActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnFirstActionPerformed
1180: {//GEN-HEADEREND:event_btnFirstActionPerformed
1181: // Add your handling code here:
1182: setPageIndex(0);
1183: refreshPage();
1184: }//GEN-LAST:event_btnFirstActionPerformed
1185:
1186: void btnReloadActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnReloadActionPerformed
1187: {//GEN-HEADEREND:event_btnReloadActionPerformed
1188: // Add your handling code here:
1189: if (type == TYPE_FILE_NAME) {
1190: try {
1191: loadReport(reportFileName, isXML);
1192: } catch (JRException e) {
1193: e.printStackTrace();
1194:
1195: jasperPrint = null;
1196: setPageIndex(0);
1197: refreshPage();
1198:
1199: JOptionPane.showMessageDialog(this ,
1200: getBundleString("error.loading"));
1201: }
1202:
1203: forceRefresh();
1204: }
1205: }//GEN-LAST:event_btnReloadActionPerformed
1206:
1207: protected void forceRefresh() {
1208: zoom = 0;//force pageRefresh()
1209: realZoom = 0f;
1210: setZoomRatio(1);
1211: }
1212:
1213: void btnZoomInActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnZoomInActionPerformed
1214: {//GEN-HEADEREND:event_btnZoomInActionPerformed
1215: // Add your handling code here:
1216: btnActualSize.setSelected(false);
1217: btnFitPage.setSelected(false);
1218: btnFitWidth.setSelected(false);
1219:
1220: int newZoomInt = (int) (100 * getZoomRatio());
1221: int index = Arrays.binarySearch(zooms, newZoomInt);
1222: if (index < 0) {
1223: setZoomRatio(zooms[-index - 1] / 100f);
1224: } else if (index < cmbZoom.getModel().getSize() - 1) {
1225: setZoomRatio(zooms[index + 1] / 100f);
1226: }
1227: }//GEN-LAST:event_btnZoomInActionPerformed
1228:
1229: void btnZoomOutActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnZoomOutActionPerformed
1230: {//GEN-HEADEREND:event_btnZoomOutActionPerformed
1231: // Add your handling code here:
1232: btnActualSize.setSelected(false);
1233: btnFitPage.setSelected(false);
1234: btnFitWidth.setSelected(false);
1235:
1236: int newZoomInt = (int) (100 * getZoomRatio());
1237: int index = Arrays.binarySearch(zooms, newZoomInt);
1238: if (index > 0) {
1239: setZoomRatio(zooms[index - 1] / 100f);
1240: } else if (index < -1) {
1241: setZoomRatio(zooms[-index - 2] / 100f);
1242: }
1243: }//GEN-LAST:event_btnZoomOutActionPerformed
1244:
1245: void cmbZoomActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cmbZoomActionPerformed
1246: {//GEN-HEADEREND:event_cmbZoomActionPerformed
1247: // Add your handling code here:
1248: float newZoom = getZoomRatio();
1249:
1250: if (newZoom < MIN_ZOOM) {
1251: newZoom = MIN_ZOOM;
1252: }
1253:
1254: if (newZoom > MAX_ZOOM) {
1255: newZoom = MAX_ZOOM;
1256: }
1257:
1258: setZoomRatio(newZoom);
1259: }//GEN-LAST:event_cmbZoomActionPerformed
1260:
1261: /**
1262: */
1263: void hyperlinkClicked(MouseEvent evt) {
1264: JPanel link = (JPanel) evt.getSource();
1265: JRPrintHyperlink element = (JRPrintHyperlink) linksMap
1266: .get(link);
1267: hyperlinkClicked(element);
1268: }
1269:
1270: protected void hyperlinkClicked(JRPrintHyperlink hyperlink) {
1271: try {
1272: JRHyperlinkListener listener = null;
1273: for (int i = 0; i < hyperlinkListeners.size(); i++) {
1274: listener = (JRHyperlinkListener) hyperlinkListeners
1275: .get(i);
1276: listener.gotoHyperlink(hyperlink);
1277: }
1278: } catch (JRException e) {
1279: e.printStackTrace();
1280: JOptionPane.showMessageDialog(this ,
1281: getBundleString("error.hyperlink"));
1282: }
1283: }
1284:
1285: /**
1286: */
1287: public int getPageIndex() {
1288: return pageIndex;
1289: }
1290:
1291: /**
1292: */
1293: private void setPageIndex(int index) {
1294: if (index > -1 && index < jasperPrint.getPages().size()) {
1295:
1296: if (jasperPrint != null && jasperPrint.getPages() != null
1297: && jasperPrint.getPages().size() > 0) {
1298: pageIndex = index;
1299: btnFirst.setEnabled((pageIndex > 0));
1300: btnPrevious.setEnabled((pageIndex > 0));
1301: btnNext.setEnabled((pageIndex < jasperPrint.getPages()
1302: .size() - 1));
1303: btnLast.setEnabled((pageIndex < jasperPrint.getPages()
1304: .size() - 1));
1305: txtGoTo.setEnabled(btnFirst.isEnabled()
1306: || btnLast.isEnabled());
1307: txtGoTo.setText("" + (pageIndex + 1));
1308: lblStatus.setText(MessageFormat.format(
1309: getBundleString("page"), new Object[] {
1310: new Integer(pageIndex + 1),
1311: new Integer(jasperPrint.getPages()
1312: .size()) }));
1313: } else {
1314: btnFirst.setEnabled(false);
1315: btnPrevious.setEnabled(false);
1316: btnNext.setEnabled(false);
1317: btnLast.setEnabled(false);
1318: txtGoTo.setEnabled(false);
1319: txtGoTo.setText("");
1320: lblStatus.setText("");
1321: }
1322: }
1323: }
1324:
1325: /**
1326: */
1327: protected void loadReport(String fileName, boolean isXmlReport)
1328: throws JRException {
1329: if (isXmlReport) {
1330: jasperPrint = JRPrintXmlLoader.load(fileName);
1331: } else {
1332: jasperPrint = (JasperPrint) JRLoader.loadObject(fileName);
1333: }
1334:
1335: type = TYPE_FILE_NAME;
1336: this .isXML = isXmlReport;
1337: reportFileName = fileName;
1338: btnReload.setEnabled(true);
1339: setPageIndex(0);
1340: }
1341:
1342: /**
1343: */
1344: protected void loadReport(InputStream is, boolean isXmlReport)
1345: throws JRException {
1346: if (isXmlReport) {
1347: jasperPrint = JRPrintXmlLoader.load(is);
1348: } else {
1349: jasperPrint = (JasperPrint) JRLoader.loadObject(is);
1350: }
1351:
1352: type = TYPE_INPUT_STREAM;
1353: this .isXML = isXmlReport;
1354: btnReload.setEnabled(false);
1355: setPageIndex(0);
1356: }
1357:
1358: /**
1359: */
1360: protected void loadReport(JasperPrint jrPrint) {
1361: jasperPrint = jrPrint;
1362: type = TYPE_OBJECT;
1363: isXML = false;
1364: btnReload.setEnabled(false);
1365: setPageIndex(0);
1366: }
1367:
1368: /**
1369: */
1370: protected void refreshPage() {
1371: if (jasperPrint == null || jasperPrint.getPages() == null
1372: || jasperPrint.getPages().size() == 0) {
1373: pnlPage.setVisible(false);
1374: btnSave.setEnabled(false);
1375: btnPrint.setEnabled(false);
1376: btnActualSize.setEnabled(false);
1377: btnFitPage.setEnabled(false);
1378: btnFitWidth.setEnabled(false);
1379: btnZoomIn.setEnabled(false);
1380: btnZoomOut.setEnabled(false);
1381: cmbZoom.setEnabled(false);
1382:
1383: if (jasperPrint != null) {
1384: JOptionPane.showMessageDialog(this ,
1385: getBundleString("no.pages"));
1386: }
1387:
1388: return;
1389: }
1390:
1391: pnlPage.setVisible(true);
1392: btnSave.setEnabled(true);
1393: btnPrint.setEnabled(true);
1394: btnActualSize.setEnabled(true);
1395: btnFitPage.setEnabled(true);
1396: btnFitWidth.setEnabled(true);
1397: btnZoomIn.setEnabled(zoom < MAX_ZOOM);
1398: btnZoomOut.setEnabled(zoom > MIN_ZOOM);
1399: cmbZoom.setEnabled(true);
1400:
1401: Dimension dim = new Dimension(
1402: (int) (jasperPrint.getPageWidth() * realZoom) + 8, // 2 from border, 5 from shadow and 1 extra pixel for image
1403: (int) (jasperPrint.getPageHeight() * realZoom) + 8);
1404: pnlPage.setMaximumSize(dim);
1405: pnlPage.setMinimumSize(dim);
1406: pnlPage.setPreferredSize(dim);
1407:
1408: long maxImageSize = JRProperties
1409: .getLongProperty(VIEWER_RENDER_BUFFER_MAX_SIZE);
1410: boolean renderImage;
1411: if (maxImageSize <= 0) {
1412: renderImage = false;
1413: } else {
1414: long imageSize = JRPrinterAWT.getImageSize(jasperPrint,
1415: realZoom);
1416: renderImage = imageSize <= maxImageSize;
1417: }
1418:
1419: lblPage.setRenderImage(renderImage);
1420:
1421: if (renderImage) {
1422: Image image = null;
1423: ImageIcon imageIcon = null;
1424: try {
1425: image = JasperPrintManager.printPageToImage(
1426: jasperPrint, pageIndex, realZoom);
1427: imageIcon = new ImageIcon(image);
1428: } catch (Exception e) {
1429: e.printStackTrace();
1430: JOptionPane.showMessageDialog(this ,
1431: java.util.ResourceBundle.getBundle(
1432: "net/sf/jasperreports/view/viewer")
1433: .getString("error.displaying"));
1434: }
1435:
1436: lblPage.setIcon(imageIcon);
1437: }
1438:
1439: pnlLinks.removeAll();
1440: linksMap = new HashMap();
1441:
1442: createHyperlinks();
1443:
1444: if (!renderImage) {
1445: lblPage.setIcon(null);
1446:
1447: pnlMain.validate();
1448: pnlMain.repaint();
1449: }
1450: }
1451:
1452: protected void createHyperlinks() {
1453: java.util.List pages = jasperPrint.getPages();
1454: JRPrintPage page = (JRPrintPage) pages.get(pageIndex);
1455: createHyperlinks(page.getElements(), 0, 0);
1456: }
1457:
1458: protected void createHyperlinks(List elements, int offsetX,
1459: int offsetY) {
1460: if (elements != null && elements.size() > 0) {
1461: for (Iterator it = elements.iterator(); it.hasNext();) {
1462: JRPrintElement element = (JRPrintElement) it.next();
1463:
1464: JRImageMapRenderer imageMap = null;
1465: if (element instanceof JRPrintImage) {
1466: JRRenderable renderer = ((JRPrintImage) element)
1467: .getRenderer();
1468: if (renderer instanceof JRImageMapRenderer) {
1469: imageMap = (JRImageMapRenderer) renderer;
1470: }
1471: }
1472: boolean hasImageMap = imageMap != null;
1473:
1474: JRPrintHyperlink hyperlink = null;
1475: if (!hasImageMap && element instanceof JRPrintHyperlink) {
1476: hyperlink = (JRPrintHyperlink) element;
1477: }
1478: boolean hasHyperlink = hyperlink != null
1479: && hyperlink.getHyperlinkType() != JRHyperlink.HYPERLINK_TYPE_NONE;
1480:
1481: if (hasHyperlink || hasImageMap) {
1482: JPanel link;
1483: if (hasHyperlink) {
1484: link = new JPanel();
1485: link.addMouseListener(mouseListener);
1486: } else //hasImageMap
1487: {
1488: Rectangle renderingArea = new Rectangle(0, 0,
1489: element.getWidth(), element.getHeight());
1490: link = new ImageMapPanel(renderingArea,
1491: imageMap);
1492: }
1493:
1494: if (hasHyperlink) {
1495: link.setCursor(new Cursor(Cursor.HAND_CURSOR));
1496: }
1497:
1498: link
1499: .setLocation(
1500: (int) ((element.getX() + offsetX) * realZoom),
1501: (int) ((element.getY() + offsetY) * realZoom));
1502: link.setSize((int) (element.getWidth() * realZoom),
1503: (int) (element.getHeight() * realZoom));
1504: link.setOpaque(false);
1505:
1506: String toolTip;
1507: if (hasHyperlink) {
1508: toolTip = getHyperlinkTooltip(hyperlink);
1509: } else //hasImageMap
1510: {
1511: toolTip = "";//not null to register the panel as having a tool tip
1512: }
1513: link.setToolTipText(toolTip);
1514:
1515: pnlLinks.add(link);
1516: linksMap.put(link, element);
1517: }
1518:
1519: if (element instanceof JRPrintFrame) {
1520: JRPrintFrame frame = (JRPrintFrame) element;
1521: int frameOffsetX = offsetX + frame.getX()
1522: + frame.getLeftPadding();
1523: int frameOffsetY = offsetY + frame.getY()
1524: + frame.getTopPadding();
1525: createHyperlinks(frame.getElements(), frameOffsetX,
1526: frameOffsetY);
1527: }
1528: }
1529: }
1530: }
1531:
1532: protected class ImageMapPanel extends JPanel implements
1533: MouseListener, MouseMotionListener {
1534: protected final List imageAreaHyperlinks;
1535:
1536: public ImageMapPanel(Rectangle renderingArea,
1537: JRImageMapRenderer imageMap) {
1538: try {
1539: imageAreaHyperlinks = imageMap
1540: .getImageAreaHyperlinks(renderingArea);
1541: } catch (JRException e) {
1542: throw new JRRuntimeException(e);
1543: }
1544:
1545: addMouseListener(this );
1546: addMouseMotionListener(this );
1547: }
1548:
1549: public String getToolTipText(MouseEvent event) {
1550: String tooltip = null;
1551: JRPrintImageAreaHyperlink imageMapArea = getImageMapArea(event);
1552: if (imageMapArea != null) {
1553: tooltip = getHyperlinkTooltip(imageMapArea
1554: .getHyperlink());
1555: }
1556:
1557: if (tooltip == null) {
1558: tooltip = super .getToolTipText(event);
1559: }
1560:
1561: return tooltip;
1562: }
1563:
1564: public void mouseDragged(MouseEvent e) {
1565: }
1566:
1567: public void mouseMoved(MouseEvent e) {
1568: JRPrintImageAreaHyperlink imageArea = getImageMapArea(e);
1569: if (imageArea != null
1570: && imageArea.getHyperlink().getHyperlinkType() != JRHyperlink.HYPERLINK_TYPE_NONE) {
1571: e.getComponent().setCursor(
1572: Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1573: } else {
1574: e.getComponent().setCursor(Cursor.getDefaultCursor());
1575: }
1576: }
1577:
1578: protected JRPrintImageAreaHyperlink getImageMapArea(MouseEvent e) {
1579: return getImageMapArea((int) (e.getX() / realZoom),
1580: (int) (e.getY() / realZoom));
1581: }
1582:
1583: protected JRPrintImageAreaHyperlink getImageMapArea(int x, int y) {
1584: JRPrintImageAreaHyperlink image = null;
1585: for (Iterator it = imageAreaHyperlinks.iterator(); image == null
1586: && it.hasNext();) {
1587: JRPrintImageAreaHyperlink area = (JRPrintImageAreaHyperlink) it
1588: .next();
1589: if (area.getArea().containsPoint(x, y)) {
1590: image = area;
1591: }
1592: }
1593: return image;
1594: }
1595:
1596: public void mouseClicked(MouseEvent e) {
1597: JRPrintImageAreaHyperlink imageMapArea = getImageMapArea(e);
1598: if (imageMapArea != null) {
1599: hyperlinkClicked(imageMapArea.getHyperlink());
1600: }
1601: }
1602:
1603: public void mouseEntered(MouseEvent e) {
1604: }
1605:
1606: public void mouseExited(MouseEvent e) {
1607: }
1608:
1609: public void mousePressed(MouseEvent e) {
1610: }
1611:
1612: public void mouseReleased(MouseEvent e) {
1613: }
1614: }
1615:
1616: protected String getHyperlinkTooltip(JRPrintHyperlink hyperlink) {
1617: String toolTip;
1618: toolTip = hyperlink.getHyperlinkTooltip();
1619: if (toolTip == null) {
1620: toolTip = getFallbackTooltip(hyperlink);
1621: }
1622: return toolTip;
1623: }
1624:
1625: protected String getFallbackTooltip(JRPrintHyperlink hyperlink) {
1626: String toolTip = null;
1627: switch (hyperlink.getHyperlinkType()) {
1628: case JRHyperlink.HYPERLINK_TYPE_REFERENCE: {
1629: toolTip = hyperlink.getHyperlinkReference();
1630: break;
1631: }
1632: case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR: {
1633: if (hyperlink.getHyperlinkAnchor() != null) {
1634: toolTip = "#" + hyperlink.getHyperlinkAnchor();
1635: }
1636: break;
1637: }
1638: case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE: {
1639: if (hyperlink.getHyperlinkPage() != null) {
1640: toolTip = "#page " + hyperlink.getHyperlinkPage();
1641: }
1642: break;
1643: }
1644: case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR: {
1645: toolTip = "";
1646: if (hyperlink.getHyperlinkReference() != null) {
1647: toolTip = toolTip + hyperlink.getHyperlinkReference();
1648: }
1649: if (hyperlink.getHyperlinkAnchor() != null) {
1650: toolTip = toolTip + "#"
1651: + hyperlink.getHyperlinkAnchor();
1652: }
1653: break;
1654: }
1655: case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE: {
1656: toolTip = "";
1657: if (hyperlink.getHyperlinkReference() != null) {
1658: toolTip = toolTip + hyperlink.getHyperlinkReference();
1659: }
1660: if (hyperlink.getHyperlinkPage() != null) {
1661: toolTip = toolTip + "#page "
1662: + hyperlink.getHyperlinkPage();
1663: }
1664: break;
1665: }
1666: default: {
1667: break;
1668: }
1669: }
1670: return toolTip;
1671: }
1672:
1673: /**
1674: */
1675: private void emptyContainer(Container container) {
1676: Component[] components = container.getComponents();
1677:
1678: if (components != null) {
1679: for (int i = 0; i < components.length; i++) {
1680: if (components[i] instanceof Container) {
1681: emptyContainer((Container) components[i]);
1682: }
1683: }
1684: }
1685:
1686: components = null;
1687: container.removeAll();
1688: container = null;
1689: }
1690:
1691: /**
1692: */
1693: private float getZoomRatio() {
1694: float newZoom = zoom;
1695:
1696: try {
1697: newZoom = zoomDecimalFormat.parse(
1698: String.valueOf(cmbZoom.getEditor().getItem()))
1699: .floatValue() / 100f;
1700: } catch (ParseException e) {
1701: }
1702:
1703: return newZoom;
1704: }
1705:
1706: /**
1707: */
1708: public void setZoomRatio(float newZoom) {
1709: if (newZoom > 0) {
1710: cmbZoom.getEditor().setItem(
1711: zoomDecimalFormat.format(newZoom * 100) + "%");
1712:
1713: if (zoom != newZoom) {
1714: zoom = newZoom;
1715: realZoom = zoom * screenResolution / REPORT_RESOLUTION;
1716:
1717: refreshPage();
1718: }
1719: }
1720: }
1721:
1722: /**
1723: */
1724: private void setRealZoomRatio(float newZoom) {
1725: if (newZoom > 0 && realZoom != newZoom) {
1726: zoom = newZoom * REPORT_RESOLUTION / screenResolution;
1727: realZoom = newZoom;
1728:
1729: cmbZoom.getEditor().setItem(
1730: zoomDecimalFormat.format(zoom * 100) + "%");
1731:
1732: refreshPage();
1733: }
1734: }
1735:
1736: /**
1737: *
1738: */
1739: public void setFitWidthZoomRatio() {
1740: setRealZoomRatio(((float) pnlInScroll.getVisibleRect()
1741: .getWidth() - 20f)
1742: / jasperPrint.getPageWidth());
1743:
1744: }
1745:
1746: public void setFitPageZoomRatio() {
1747: setRealZoomRatio(((float) pnlInScroll.getVisibleRect()
1748: .getHeight() - 20f)
1749: / jasperPrint.getPageHeight());
1750: }
1751:
1752: /**
1753: */
1754: protected void paintPage(Graphics2D grx) {
1755: try {
1756: if (exporter == null) {
1757: exporter = new JRGraphics2DExporter();
1758: } else {
1759: exporter.reset();
1760: }
1761:
1762: exporter.setParameter(JRExporterParameter.JASPER_PRINT,
1763: jasperPrint);
1764: exporter.setParameter(
1765: JRGraphics2DExporterParameter.GRAPHICS_2D, grx);
1766: exporter.setParameter(JRExporterParameter.PAGE_INDEX,
1767: new Integer(pageIndex));
1768: exporter.setParameter(
1769: JRGraphics2DExporterParameter.ZOOM_RATIO,
1770: new Float(realZoom));
1771: exporter.setParameter(JRExporterParameter.OFFSET_X,
1772: new Integer(1)); //lblPage border
1773: exporter.setParameter(JRExporterParameter.OFFSET_Y,
1774: new Integer(1));
1775: exporter.exportReport();
1776: } catch (Exception e) {
1777: e.printStackTrace();
1778: JOptionPane.showMessageDialog(this ,
1779: getBundleString("error.displaying"));
1780: }
1781:
1782: }
1783:
1784: private void keyNavigate(KeyEvent evt) {
1785: switch (evt.getKeyCode()) {
1786: case KeyEvent.VK_DOWN:
1787: case KeyEvent.VK_PAGE_DOWN:
1788: dnNavigate(evt);
1789: break;
1790: case KeyEvent.VK_UP:
1791: case KeyEvent.VK_PAGE_UP:
1792: upNavigate(evt);
1793: break;
1794: case KeyEvent.VK_HOME:
1795: homeEndNavigate(0);
1796: break;
1797: case KeyEvent.VK_END:
1798: homeEndNavigate(jasperPrint.getPages().size() - 1);
1799: break;
1800: default:
1801:
1802: }
1803: refreshPage();
1804: }
1805:
1806: private void dnNavigate(KeyEvent evt) {
1807: int bottomPosition = scrollPane.getVerticalScrollBar()
1808: .getValue();
1809: scrollPane.dispatchEvent(evt);
1810: if ((scrollPane.getViewport().getHeight() > pnlPage.getHeight() || scrollPane
1811: .getVerticalScrollBar().getValue() == bottomPosition)
1812: && pageIndex < jasperPrint.getPages().size() - 1) {
1813: setPageIndex(pageIndex + 1);
1814: if (scrollPane.isEnabled())
1815: scrollPane.getVerticalScrollBar().setValue(0);
1816: }
1817: }
1818:
1819: private void upNavigate(KeyEvent evt) {
1820: if ((scrollPane.getViewport().getHeight() > pnlPage.getHeight() || scrollPane
1821: .getVerticalScrollBar().getValue() == 0)
1822: && pageIndex > 0) {
1823: setPageIndex(pageIndex - 1);
1824: if (scrollPane.isEnabled())
1825: scrollPane.getVerticalScrollBar().setValue(
1826: scrollPane.getVerticalScrollBar().getMaximum());
1827: } else {
1828: scrollPane.dispatchEvent(evt);
1829: }
1830: }
1831:
1832: private void homeEndNavigate(int pageNumber) {
1833: setPageIndex(pageNumber);
1834: if (scrollPane.isEnabled())
1835: scrollPane.getVerticalScrollBar().setValue(0);
1836: }
1837:
1838: /**
1839: *
1840: */
1841: private void fitPage() {
1842: float heightRatio = ((float) pnlInScroll.getVisibleRect()
1843: .getHeight() - 20f)
1844: / jasperPrint.getPageHeight();
1845: float widthRatio = ((float) pnlInScroll.getVisibleRect()
1846: .getWidth() - 20f)
1847: / jasperPrint.getPageWidth();
1848: setRealZoomRatio(heightRatio < widthRatio ? heightRatio
1849: : widthRatio);
1850: }
1851:
1852: /**
1853: */
1854: class PageRenderer extends JLabel {
1855: private boolean renderImage;
1856: JRViewer viewer = null;
1857:
1858: public PageRenderer(JRViewer viewer) {
1859: this .viewer = viewer;
1860: }
1861:
1862: public void paintComponent(Graphics g) {
1863: if (isRenderImage()) {
1864: super .paintComponent(g);
1865: } else {
1866: viewer.paintPage((Graphics2D) g.create());
1867: }
1868: }
1869:
1870: public boolean isRenderImage() {
1871: return renderImage;
1872: }
1873:
1874: public void setRenderImage(boolean renderImage) {
1875: this .renderImage = renderImage;
1876: }
1877: }
1878:
1879: // Variables declaration - do not modify//GEN-BEGIN:variables
1880: protected javax.swing.JToggleButton btnActualSize;
1881: protected javax.swing.JButton btnFirst;
1882: protected javax.swing.JToggleButton btnFitPage;
1883: protected javax.swing.JToggleButton btnFitWidth;
1884: protected javax.swing.JButton btnLast;
1885: protected javax.swing.JButton btnNext;
1886: protected javax.swing.JButton btnPrevious;
1887: protected javax.swing.JButton btnPrint;
1888: protected javax.swing.JButton btnReload;
1889: protected javax.swing.JButton btnSave;
1890: protected javax.swing.JButton btnZoomIn;
1891: protected javax.swing.JButton btnZoomOut;
1892: protected javax.swing.JComboBox cmbZoom;
1893: private javax.swing.JLabel jLabel1;
1894: private javax.swing.JPanel jPanel4;
1895: private javax.swing.JPanel jPanel5;
1896: private javax.swing.JPanel jPanel6;
1897: private javax.swing.JPanel jPanel7;
1898: private javax.swing.JPanel jPanel8;
1899: private javax.swing.JPanel jPanel9;
1900: private PageRenderer lblPage;
1901: protected javax.swing.JLabel lblStatus;
1902: private javax.swing.JPanel pnlInScroll;
1903: private javax.swing.JPanel pnlLinks;
1904: private javax.swing.JPanel pnlMain;
1905: private javax.swing.JPanel pnlPage;
1906: protected javax.swing.JPanel pnlSep01;
1907: protected javax.swing.JPanel pnlSep02;
1908: protected javax.swing.JPanel pnlSep03;
1909: protected javax.swing.JPanel pnlStatus;
1910: private javax.swing.JScrollPane scrollPane;
1911: protected javax.swing.JPanel tlbToolBar;
1912: protected javax.swing.JTextField txtGoTo;
1913: // End of variables declaration//GEN-END:variables
1914:
1915: }
|