📄 previewproxybase.java
字号:
/**
* ========================================
* JFreeReport : a free Java report library
* ========================================
*
* Project Info: http://www.jfree.org/jfreereport/index.html
* Project Lead: Thomas Morgner;
*
* (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ---------------------
* PreviewProxyBase.java
* ---------------------
* (C)opyright 2003, by Simba Management Limited and Contributors.
*
* Original Author: Thomas Morgner;
* Contributor(s): David Gilbert (for Simba Management Limited);
*
* $Id: PreviewProxyBase.java,v 1.26.2.5 2003/08/24 15:10:36 taqua Exp $
*
* Changes
* -------
* 25-Feb-2003 : Added standard header and Javadocs (DG);
*
*/
package com.jrefinery.report.preview;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.print.PageFormat;
import java.awt.print.Pageable;
import java.awt.print.Printable;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.ResourceBundle;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.RepaintManager;
import javax.swing.UIManager;
import com.jrefinery.report.JFreeReport;
import com.jrefinery.report.ReportProcessingException;
import com.jrefinery.report.action.AboutAction;
import com.jrefinery.report.action.FirstPageAction;
import com.jrefinery.report.action.GotoPageAction;
import com.jrefinery.report.action.LastPageAction;
import com.jrefinery.report.action.NextPageAction;
import com.jrefinery.report.action.PreviousPageAction;
import com.jrefinery.report.action.ZoomInAction;
import com.jrefinery.report.action.ZoomOutAction;
import com.jrefinery.report.targets.base.bandlayout.LayoutManagerCache;
import com.jrefinery.report.targets.base.event.RepaginationListener;
import com.jrefinery.report.util.AbstractActionDowngrade;
import com.jrefinery.report.util.ActionButton;
import com.jrefinery.report.util.ActionDowngrade;
import com.jrefinery.report.util.ActionMenuItem;
import com.jrefinery.report.util.ExceptionDialog;
import com.jrefinery.report.util.FloatingButtonEnabler;
import com.jrefinery.report.util.Log;
import com.jrefinery.report.util.ReportConfiguration;
import com.jrefinery.report.util.WindowSizeLimiter;
import com.jrefinery.report.util.Worker;
import com.jrefinery.report.util.ActionConcentrator;
import org.jfree.layout.CenterLayout;
import org.jfree.xml.ParserUtil;
import org.jfree.ui.RefineryUtilities;
import org.xml.sax.SAXException;
/**
* A preview proxy.
*
* @author Thomas Morgner.
*/
public class PreviewProxyBase extends JComponent
{
/** The worker thread which is used to perform the repagination. */
private Worker paginationWorker;
/** The worker thread which is used to perform the repagination. */
private Worker exportWorker;
/** The default width of the report pane. */
public static final int DEFAULT_REPORT_PANE_WIDTH = 640;
/** The default height of the report pane. */
public static final int DEFAULT_REPORT_PANE_HEIGHT = 480;
public static final String LARGE_ICONS_ENABLED_PROPERTY = "com.jrefinery.report.preview.LargeIconsEnabled";
public static final String TOOLBAR_FLOATABLE_PROPERTY = "com.jrefinery.report.preview.ToolbarFloatable";
/**
* A wrapper action.
*/
private class WrapperAction implements Action
{
/** The parent action. */
private Action parent;
/**
* Creates a new action.
*
* @param parent the parent action (null not permitted).
*/
public WrapperAction(final Action parent)
{
setParent(parent);
}
/**
* Returns the parent action.
*
* @return the parent action.
*/
public Action getParent()
{
return parent;
}
/**
* Sets the parent action.
*
* @param parent the parent action (null not permitted).
*/
public void setParent(final Action parent)
{
if (parent == null)
{
throw new NullPointerException();
}
this.parent = parent;
registerAction(parent);
}
/**
* Gets one of this object's properties using the associated key.
*
* @param key the key.
*
* @return the property value.
*
* @see #putValue
*/
public Object getValue(final String key)
{
return parent.getValue(key);
}
/**
* Invoked when an action occurs.
*
* @param e the event.
*/
public void actionPerformed(final ActionEvent e)
{
parent.actionPerformed(e);
}
/**
* Sets one of this object's properties
* using the associated key. If the value has
* changed, a <code>PropertyChangeEvent</code> is sent
* to listeners.
*
* @param key a <code>String</code> containing the key.
* @param value an <code>Object</code> value.
*/
public void putValue(final String key, final Object value)
{
parent.putValue(key, value);
}
/**
* Sets the enabled state of the <code>Action</code>. When enabled,
* any component associated with this object is active and
* able to fire this object's <code>actionPerformed</code> method.
* If the value has changed, a <code>PropertyChangeEvent</code> is sent
* to listeners.
*
* @param b true to enable this <code>Action</code>, false to disable it.
*/
public void setEnabled(final boolean b)
{
parent.setEnabled(b);
}
/**
* Returns the enabled state of the <code>Action</code>. When enabled,
* any component associated with this object is active and
* able to fire this object's <code>actionPerformed</code> method.
*
* @return true if this <code>Action</code> is enabled.
*/
public boolean isEnabled()
{
return parent.isEnabled();
}
/**
* Adds a <code>PropertyChange</code> listener. Containers and attached
* components use these methods to register interest in this
* <code>Action</code> object. When its enabled state or other property
* changes, the registered listeners are informed of the change.
*
* @param listener a <code>PropertyChangeListener</code> object.
*/
public void addPropertyChangeListener(final PropertyChangeListener listener)
{
parent.addPropertyChangeListener(listener);
}
/**
* Removes a <code>PropertyChange</code> listener.
*
* @param listener a <code>PropertyChangeListener</code> object
* @see #addPropertyChangeListener
*/
public void removePropertyChangeListener(final PropertyChangeListener listener)
{
parent.removePropertyChangeListener(listener);
}
}
/**
* A property change listener.
*/
private class ReportPanePropertyChangeListener implements PropertyChangeListener
{
/**
* Creates a new listener.
*/
public ReportPanePropertyChangeListener()
{
}
/**
* Listen to the assigned reportPane.
*
* @param event the property change event.
*/
public void propertyChange(final PropertyChangeEvent event)
{
final String property = event.getPropertyName();
final ReportPane reportPane = getReportPane();
if (property.equals(ReportPane.PAGINATED_PROPERTY))
{
if (reportPane.isPaginated())
{
// is paginated ...
final Object[] params = new Object[]{
new Integer(reportPane.getPageNumber()),
new Integer(reportPane.getNumberOfPages())
};
setStatusText(
MessageFormat.format(
getResources().getString("statusline.pages"),
params
)
);
validateButtons();
}
else
{
// is not paginated ... ignore event ...
}
}
else if (property.equals(ReportPane.PAGENUMBER_PROPERTY)
|| property.equals(ReportPane.NUMBER_OF_PAGES_PROPERTY))
{
final Object[] params = new Object[]{
new Integer(reportPane.getPageNumber()),
new Integer(reportPane.getNumberOfPages())
};
setStatusText(
MessageFormat.format(
getResources().getString("statusline.pages"),
params
)
);
validateButtons();
}
else if (property.equals(ReportPane.ERROR_PROPERTY))
{
if (reportPane.hasError())
{
final Exception ex = reportPane.getError();
ex.printStackTrace();
setStatusText(
MessageFormat.format(
getResources().getString("statusline.error"),
new Object[]{ex.getMessage()}
)
);
}
validateButtons();
}
else if (property.equals(ReportPane.ZOOMFACTOR_PROPERTY))
{
validateButtons();
validate();
}
}
}
/**
* Default 'first page' action.
*/
private class DefaultFirstPageAction extends FirstPageAction
{
/**
* Creates a 'first page' action.
*/
public DefaultFirstPageAction()
{
super(getResources());
}
/**
* Jump to the first page of the report.
*
* @param e The action event.
*
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(final ActionEvent e)
{
firstPage();
}
}
/**
* Default 'next page' action for the frame.
*/
private class DefaultNextPageAction extends NextPageAction
{
/**
* Creates a 'next page' action.
*/
public DefaultNextPageAction()
{
super(getResources());
}
/**
* show the next page of the report.
*
* @param e The action event.
*/
public void actionPerformed(final ActionEvent e)
{
increasePageNumber();
}
}
/**
* Default 'previous page' action for the frame.
*/
private class DefaultPreviousPageAction extends PreviousPageAction
{
/**
* Creates a 'previous page' action.
*/
public DefaultPreviousPageAction()
{
super(getResources());
}
/**
* show the previous page of the report.
* @param e The action event.
*/
public void actionPerformed(final ActionEvent e)
{
decreasePageNumber();
}
}
/**
* Default 'last page' action for the frame.
*/
private class DefaultLastPageAction extends LastPageAction
{
/**
* Creates a 'last page' action.
*/
public DefaultLastPageAction()
{
super(getResources());
}
/**
* jump to the last page of the report.
*
* @param e The action event.
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(final ActionEvent e)
{
lastPage();
}
}
/**
* Default 'zoom in' action for the frame.
*/
private class DefaultZoomInAction extends ZoomInAction
{
/**
* Creates a 'zoom in' action.
*/
public DefaultZoomInAction()
{
super(getResources());
}
/**
* increase zoom.
* @param e The action event.
*/
public void actionPerformed(final ActionEvent e)
{
increaseZoom();
}
}
/**
* Default 'zoom out' action for the frame.
*/
private class DefaultZoomOutAction extends ZoomOutAction
{
/**
* Creates a 'zoom out' action.
*/
public DefaultZoomOutAction()
{
super(getResources());
}
/**
* decrease zoom.
* @param e The action event.
*/
public void actionPerformed(final ActionEvent e)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -