📄 previewproxybase.java
字号:
final ReportPane reportPane = new ReportPane(report);
return reportPane;
}
/**
* Retrieves the resources for this PreviewFrame. If the resources are not initialized,
* they get loaded on the first call to this method.
*
* @return this frames ResourceBundle.
*/
protected ResourceBundle getResources()
{
if (resources == null)
{
resources = ResourceBundle.getBundle(BASE_RESOURCE_CLASS);
}
return resources;
}
/**
* Returns the current zoom factor.
*
* @return The current zoom factor.
*/
public float getZoomFactor()
{
return ZOOM_FACTORS[zoomIndex];
}
/**
* Returns the report pane, which implements the Pageable interface.
*
* @return the report pane.
*/
public Pageable getPageable()
{
return reportPane;
}
/**
* Returns the report pane, which implements the Printable interface.
*
* @return the report pane.
*/
public Printable getPrintable()
{
return reportPane;
}
/**
* Returns the report pane used to preview the report.
*
* @return the report pane.
*/
protected ReportPane getReportPane()
{
return reportPane;
}
/**
* Shows the exception dialog by using localized messages. The message base is
* used to construct the localisation key by appending ".title" and ".message" to the
* base name.
*
* @param localisationBase the resource key prefix.
* @param e the exception.
*/
protected void showExceptionDialog(final String localisationBase, final Exception e)
{
ExceptionDialog.showExceptionDialog(
getResources().getString(localisationBase + ".title"),
MessageFormat.format(
getResources().getString(localisationBase + ".message"),
new Object[]{e.getLocalizedMessage()}
),
e);
}
/**
* Method lastPage moves to the last page.
*/
protected void lastPage()
{
reportPane.setPageNumber(reportPane.getNumberOfPages());
}
/**
* Increases the page number.
*/
protected void increasePageNumber()
{
final int pn = reportPane.getPageNumber();
final int mp = reportPane.getNumberOfPages();
if (pn < mp)
{
reportPane.setPageNumber(pn + 1);
}
}
/**
* Activates the display of the first page, if not already on the first page.
*/
protected void firstPage()
{
if (reportPane.getPageNumber() != 1)
{
reportPane.setPageNumber(1);
}
}
/**
* Decreases the page number.
*/
protected void decreasePageNumber()
{
final int pn = reportPane.getPageNumber();
if (pn > 1)
{
reportPane.setPageNumber(pn - 1);
}
}
/**
* Increases the zoom factor for the report pane (unless it is already at maximum zoom).
*/
protected void increaseZoom()
{
if (zoomIndex < ZOOM_FACTORS.length - 1)
{
zoomIndex++;
}
zoomSelect.setSelectedIndex(zoomIndex);
reportPane.setZoomFactor(getZoomFactor());
//validateButtons();
}
/**
* Decreases the zoom factor for the report pane (unless it is already at the minimum zoom).
* */
protected void decreaseZoom()
{
if (zoomIndex > 0)
{
zoomIndex--;
}
zoomSelect.setSelectedIndex(zoomIndex);
reportPane.setZoomFactor(getZoomFactor());
//validateButtons();
}
/**
* Sets the zoomfactor of the report pane.
*
* @param index the index into the array of standard zoom factors.
*/
public void setZoomFactor(final int index)
{
zoomIndex = index;
reportPane.setZoomFactor(getZoomFactor());
zoomSelect.setSelectedIndex(zoomIndex);
}
/**
* Checks whether this action has a keystroke assigned. If it has one, the keystroke
* is assigned to the frame.
*
* @param action the action.
*/
protected void registerAction(final Action action)
{
final KeyStroke key = (KeyStroke) action.getValue(ActionDowngrade.ACCELERATOR_KEY);
if (key != null)
{
registerKeyboardAction(action, key, JComponent.WHEN_IN_FOCUSED_WINDOW);
}
}
/**
* Creates all actions by calling the createXXXAction functions and assigning them to
* the local variables.
*
* @param defaultCloseAction the default close action.
*/
private void createDefaultActions(final Action defaultCloseAction)
{
gotoAction = new WrapperAction(createDefaultGotoAction());
aboutAction = new WrapperAction(createDefaultAboutAction());
closeAction = new WrapperAction(defaultCloseAction);
firstPageAction = new WrapperAction(createDefaultFirstPageAction());
lastPageAction = new WrapperAction(createDefaultLastPageAction());
nextPageAction = new WrapperAction(createDefaultNextPageAction());
previousPageAction = new WrapperAction(createDefaultPreviousPageAction());
zoomInAction = new WrapperAction(createDefaultZoomInAction());
zoomOutAction = new WrapperAction(createDefaultZoomOutAction());
zoomActionConcentrator.addAction(zoomInAction);
zoomActionConcentrator.addAction(zoomOutAction);
}
/**
* Creates the NextPageAction used in this previewframe.
*
* @return the 'next page' action.
*/
protected Action createDefaultNextPageAction()
{
return new DefaultNextPageAction();
}
/**
* Creates the PreviousPageAction used in this previewframe.
*
* @return the 'previous page' action.
*/
protected Action createDefaultPreviousPageAction()
{
return new DefaultPreviousPageAction();
}
/**
* Creates the ZoomInAction used in this previewframe.
*
* @return the 'zoom in' action.
*/
protected Action createDefaultZoomInAction()
{
return new DefaultZoomInAction();
}
/**
* Creates the ZoomOutAction used in this previewframe.
*
* @return the 'zoom out' action.
*/
protected Action createDefaultZoomOutAction()
{
return new DefaultZoomOutAction();
}
/**
* Creates the AboutAction used in this previewframe.
* <P>
* If you subclass PreviewFrame, and override this method, you can display your own 'about'
* dialog.
*
* @return the 'about' action.
*/
protected Action createDefaultAboutAction()
{
return new DefaultAboutAction();
}
/**
* Creates a zoom select action.
*
* @return the action.
*/
protected Action createZoomSelectAction()
{
return new ZoomSelectAction();
}
/**
* Creates the GotoPageAction used in this previewframe.
*
* @return the 'goto' action.
*/
protected Action createDefaultGotoAction()
{
return new DefaultGotoAction();
}
/**
* Creates the FirstPageAction used in this previewframe.
*
* @return the 'first page' action.
*/
protected Action createDefaultFirstPageAction()
{
return new DefaultFirstPageAction();
}
/**
* Creates the LastPageAction used in this previewframe.
*
* @return the 'last page' action.
*/
protected Action createDefaultLastPageAction()
{
return new DefaultLastPageAction();
}
/**
* Returns the status text of the status line.
*
* @return the status text.
*/
public String getStatusText()
{
return statusHolder.getText();
}
/**
* Defines the text of the status line.
*
* @param text the new text of the status line.
*/
public void setStatusText(final String text)
{
statusHolder.setText(text);
}
/**
* Creates the statusbar for this frame. Use setStatus() to display text on the status bar.
*
* @return the status bar.
*/
protected JPanel createStatusBar()
{
final JPanel statusPane = new JPanel();
statusPane.setLayout(new BorderLayout());
statusPane.setBorder(
BorderFactory.createLineBorder(UIManager.getDefaults().getColor("controlShadow")));
statusHolder = new JLabel(" ");
statusPane.setMinimumSize(statusHolder.getPreferredSize());
statusPane.add(statusHolder, BorderLayout.WEST);
return statusPane;
}
/**
* Creates and returns a menu-bar for the frame.
*
* @return A ready-made JMenuBar.
*/
protected JMenuBar createMenuBar()
{
final ResourceBundle resources = getResources();
// create the menus
final JMenuBar menuBar = new JMenuBar();
// first the file menu
final JMenu fileMenu = new JMenu(resources.getString("menu.file.name"));
Character mnemonic = (Character) resources.getObject("menu.file.mnemonic");
fileMenu.setMnemonic(mnemonic.charValue());
final Iterator it = exportPlugIns.iterator();
final boolean addedItem = it.hasNext();
while (it.hasNext())
{
final ExportPlugin plugIn = (ExportPlugin) it.next();
final ExportAction action = (ExportAction) pluginActions.get(plugIn);
if (plugIn.isSeparated())
{
fileMenu.addSeparator();
}
fileMenu.add(createMenuItem(action));
}
if (addedItem == true)
{
fileMenu.addSeparator();
}
fileMenu.add(createMenuItem(closeAction));
// the navigation menu ...
final JMenu navMenu = new JMenu(resources.getString("menu.navigation.name"));
mnemonic = (Character) resources.getObject("menu.navigation.mnemonic");
navMenu.setMnemonic(mnemonic.charValue());
navMenu.add(createMenuItem(gotoAction));
navMenu.addSeparator();
navMenu.add(createMenuItem(firstPageAction));
navMenu.add(createMenuItem(previousPageAction));
navMenu.add(createMenuItem(nextPageAction));
navMenu.add(createMenuItem(lastPageAction));
// the navigation menu ...
final JMenu zoomMenu = new JMenu(resources.getString("menu.zoom.name"));
mnemonic = (Character) resources.getObject("menu.zoom.mnemonic");
zoomMenu.setMnemonic(mnemonic.charValue());
zoomMenu.add(createMenuItem(zoomInAction));
zoomMenu.add(createMenuItem(zoomOutAction));
zoomMenu.add(new JSeparator());
for (int i = 0; i < ZOOM_FACTORS.length; i++)
{
Action action = new ZoomSetAction(i);
zoomActionConcentrator.addAction(action);
zoomMenu.add(createMenuItem(action));
}
// then the help menu
final JMenu helpMenu = new JMenu(resources.getString("menu.help.name"));
mnemonic = (Character) resources.getObject("menu.help.mnemonic");
helpMenu.setMnemonic(mnemonic.charValue());
helpMenu.add(createMenuItem(aboutAction));
// finally, glue together the menu and return it
menuBar.add(fileMenu);
menuBar.add(navMenu);
menuBar.add(zoomMenu);
menuBar.add(helpMenu);
return menuBar;
}
/**
* Creates a button using the given action properties for the button's initialisation.
*
* @param action the action used to set up the button.
*
* @return a button based on the supplied action.
*/
protected JButton createButton(final Action action)
{
final JButton button = new ActionButton(action);
if (isLargeIconsEnabled())
{
final Icon icon = (Icon) action.getValue("ICON24");
if (icon != null)
{
button.setIcon(icon);
}
}
button.setMargin(new Insets(0, 0, 0, 0));
button.setText(null);
FloatingButtonEnabler.getInstance().addButton(button);
return button;
}
/**
* Creates a menu item based on the supplied action.
*
* @param action the action.
*
* @return the menu item.
*/
protected JMenuItem createMenuItem(final Action action)
{
final JMenuItem menuItem = new ActionMenuItem(action);
final KeyStroke accelerator = (KeyStroke) action.getValue(ActionDowngrade.ACCELERATOR_KEY);
if (accelerator != null)
{
menuItem.setAccelerator(accelerator);
}
return menuItem;
}
/**
* Creates and returns a toolbar containing controls for print, page forward and backward, zoom
* in and out, and an about box.
*
* @return A completely initialized JToolBar.
*/
protected JToolBar createToolBar(boolean floatable)
{
final JToolBar toolbar = new JToolBar();
toolbar.setFloatable(floatable);
final Iterator it = exportPlugIns.iterator();
final boolean addedItem = it.hasNext();
while (it.hasNext())
{
final ExportPlugin plugIn = (ExportPlugin) it.next();
if (plugIn.isAddToToolbar() == false)
{
continue;
}
final ExportAction action = (ExportAction) pluginActions.get(plugIn);
if (plugIn.isSeparated())
{
toolbar.addSeparator();
}
toolbar.add(createButton(action));
}
if (addedItem == true)
{
toolbar.addSeparator();
}
toolbar.add(createButton(firstPageAction));
toolbar.add(createButton(previousPageAction));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -