previewproxybase.java
来自「swing编写的库存管理程序。毕业设计类」· Java 代码 · 共 2,255 行 · 第 1/5 页
JAVA
2,255 行
*
* @param report the report of this dialog.
*/
private void applyDefinedDimension(final JFreeReport report)
{
String width = report.getReportConfiguration().getConfigProperty(
PREVIEW_PREFERRED_WIDTH);
String height = report.getReportConfiguration().getConfigProperty(
PREVIEW_PREFERRED_HEIGHT);
// only apply if both values are set.
if (width != null && height != null)
{
try
{
final Dimension pref = createCorrectedDimensions
(Integer.parseInt(width), Integer.parseInt(height));
setPreferredSize(pref);
}
catch (Exception nfe)
{
Log.warn("Preferred viewport size is defined, but the specified values are invalid.");
}
}
width = report.getReportConfiguration().getConfigProperty(
PREVIEW_MAXIMUM_WIDTH);
height = report.getReportConfiguration().getConfigProperty(
PREVIEW_MAXIMUM_HEIGHT);
// only apply if at least one value is set.
if (width != null || height != null)
{
try
{
final int iWidth = (width == null)
? Short.MAX_VALUE : (int) ParserUtil.parseRelativeFloat(width, "");
final int iHeight = (height == null)
? Short.MAX_VALUE : (int) ParserUtil.parseRelativeFloat(height, "");
final Dimension pref = createCorrectedDimensions(iWidth, iHeight);
setMaximumSize(pref);
addComponentListener(new org.jfree.report.modules.gui.base.components.WindowSizeLimiter());
}
catch (Exception nfe)
{
Log.warn("Maximum viewport size is defined, but the specified values are invalid.");
}
}
}
/**
* Correct the given width and height. If the values are negative, the height and
* width is considered a proportional value where -100 corresponds to 100%.
* The proportional attributes are given is relation to the screen width and height.
*
* @param w the to be corrected width
* @param h the height that should be corrected
* @return the dimension of width and height, where all relative values are normalized.
*/
private Dimension createCorrectedDimensions(int w, int h)
{
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
if (w < 0)
{
w = (w * screenSize.width / -100);
}
if (h < 0)
{
h = (h * screenSize.height / -100);
}
return new Dimension(w, h);
}
/**
* Creates the ReportPane for the report.
*
* @param report the report for this pane.
*
* @return the report pane.
*
* @throws ReportProcessingException if there is a problem processing the report.
*/
protected ReportPane createReportPane(final JFreeReport report) throws ReportProcessingException
{
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.
*/
public 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.
*
*/
private void createDefaultActions()
{
navigationActionMap.put(GOTO_ACTION_KEY, createDefaultGotoAction());
baseActionMap.put(ABOUT_ACTION_KEY, createDefaultAboutAction());
navigationActionMap.put(FIRSTPAGE_ACTION_KEY, createDefaultFirstPageAction());
navigationActionMap.put(LASTPAGE_ACTION_KEY, createDefaultLastPageAction());
navigationActionMap.put(NEXT_PAGE_ACTION_KEY, createDefaultNextPageAction());
navigationActionMap.put(PREV_PAGE_ACTION_KEY, createDefaultPreviousPageAction());
final Action zoomInAction = createDefaultZoomInAction();
final Action zoomOutAction = createDefaultZoomOutAction();
zoomActionMap.put(ZOOM_IN_ACTION_KEY, zoomInAction);
zoomActionMap.put(ZOOM_OUT_ACTION_KEY, 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()
{
// create the menus
final JMenuBar menuBar = new JMenuBar();
menuBar.add(createFileMenu());
if (isMenuActionEnabled(ACTION_NAVIGATION_PROPERTY))
{
menuBar.add(createNavigationMenu());
}
if (isMenuActionEnabled(ACTION_ZOOM_PROPERTY))
{
menuBar.add(createZoomMenu());
}
if (isMenuActionEnabled(ACTION_ABOUT_PROPERTY))
{
menuBar.add(createHelpMenu());
}
return menuBar;
}
/**
* Creates and returns the file menu of the preview base. The actions must
* be assigned in this method.
*
* @return A ready-made FileMenu.
*/
protected JMenu createFileMenu ()
{
final ResourceBundle resources = getResources();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?