|
i-net Clear Reports | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.inet.viewer.SwingReportViewer
public class SwingReportViewer
The SwingReportViewer is the top level container for all Swing viewer elements. It is an example implementation of the com.inet.viewer.ReportViewer interface which by default has the SwingToolBar element at the top, collects the various SwingReportViews to be shown in a TabbedPane, and shows the SwingStatusBar at the bottom.
Note that the color for the space in which the report pages appear is taken from the
UI color resource under the UI property ReportViewer.UIPROP_SCROLLPANE_BACKGROUND.
If no property is found, Color.LIGHT_GRAY is taken by default.
A simple default SwingReportViewer can be created and shown in a
JFrame with the following lines of code:
URLRenderData myConnection = new URLRenderData("http://<reportserver>:9000/?report=file:c:/report1.rpt");
myConnection.setPromptOnRefresh(true);
myConnection.setReportTitle("My Test Report");
SwingReportViewer viewer = new SwingReportViewer();
viewer.addNewReportView(myConnection);
frame.getContentPane().add(viewer);
frame.pack();
frame.setVisible(true);
Note that first, a RenderData object was created (in this case, a URLRenderData object). This RenderData object is passed to the viewer to have it create a ReportView, in either createReportView(RenderData) - which simply is a factory method which creates a new ReportView but does not add it to the Viewer - or in addNewReportView(RenderData) - which first creates a ReportView (with createReportView), and then adds the newly created ReportView to the viewer.
SwingReportViewer offers various possibilities for customizing your own Viewer by either overriding certain methods, or by setting certain options. Here are a few scenarios of possibilities of how the viewer can be customized:
Each ReportView in its own JFrame
It could be that you would like to not have a TabbedPane for
various ReportViews, but rather would like to have a JFrame
opened for each ReportView which is opened. To do this, you would
use code something like the following (for each example, we assume that
we have already instanced a RenderData object called "myConnection"):
SwingReportViewer viewer = new SwingReportViewer() {
// Here we will override the default behavior of the Viewer.
// For this, we'll keep track of the various Views in a HashMap:
HashMap myMap = new HashMap();
public void addReportView(ReportView view, boolean isClosable) {
// We now override the default behavior of addReportView
// which was to open new tabs for each new view.
// Instead, we open a new frame, place the new report view
// inside it, and remember it in combination with the frame
// in our hash map.
JFrame frame = new JFrame(view.getReportData().
getReportTitle());
// So that the viewer knows which ReportView is the
// current report view (for toolbar actions, etc.), we'll
// define a WindowFocusListener so that whenever a user
// focuses on a report view window, it becomes the
// current report view.
WindowFocusListener l = new WindowFocusListener() {
public void windowGainedFocus(WindowEvent e) {
setCurrentReportView((ReportView)myMap.get(e.getWindow()));
}
public void windowLostFocus(WindowEvent e) {
}
};
myMap.put(frame,view);
// Now we simply add the view to the frame and show it:
frame.addWindowFocusListener(l);
frame.getContentPane().add(view.getComponent());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
setCurrentReportView(view);
}
};
// This is now for initializing the viewer: We create a new
// ReportView and add it to the viewer - this will end up
// calling our overridden method and opening a new Frame.
viewer.addNewReportView(myConnection);
// We also want our toolbar to be in its own frame, so we
// extract it and place it in a JFrame:
JFrame toolbar = new JFrame("Toolbar");
toolbar.getContentPane().add(viewer.getToolBar().getComponent());
toolbar.pack();
toolbar.setVisible(true);
New ReportViews into the same JFrame
If we want each newly opened ReportView to be shown in the
same frame, that is, to only show one ReportView at a time and
to "navigate" through ReportViews, we do this similarly to the last
example, except that only one Frame is created, and the ReportViews
are simply swapped within this one Frame:
SwingReportViewer viewer = new SwingReportViewer() {
// Here we will override the default behavior of the Viewer.
public void addReportView(ReportView view, boolean isClosable) {
// We now override the default behavior of addReportView
// which was to open a new tab for each new view.
// Instead, we remove all old views and replace them with the new view.
closeAllReportViews();
super.addReportView( view, isClosable );
}
};
// This initializes the viewer: We create a new
// ReportView and add it to the viewer
viewer.addNewReportView(myConnection);
JFrame viewerFrame = new JFrame("Viewer");
viewerFrame.getContentPane().add(viewer);
viewerFrame.pack();
viewerFrame.setVisible(true);
Theoretically it would be possible to actually implement navigation backwards and
forwards through ReportViews - one would simply have to store each ReportView in a
history and run through the history backwards and forwards as needed.
| Field Summary | |
|---|---|
static int |
PRINTER_USE_DEFAULT_FORMAT_IF_SIMILAR
Uses the default format of the printer if it is A4 or Letter while the report format is the other size. |
static int |
PRINTER_USE_REPORT_FORMAT
Always uses the report's paper format, even if it is similar to the printer's paper format. |
| Fields inherited from interface com.inet.viewer.ReportViewer |
|---|
PROP_STATUS_MESSAGE, UIPROP_SCROLLPANE_BACKGROUND |
| Constructor Summary | |
|---|---|
SwingReportViewer()
Creates an instance of the SwingReportViewer, initializing a set of Actions and a SwingToolBar. |
|
SwingReportViewer(ViewerContext context)
Creates an instance of the SwingReportViewer with the given ViewerContext for handling various actions |
|
| Method Summary | |
|---|---|
ReportView |
addNewReportView(RenderData data,
boolean isClosable)
Creates a new ReportView object, using the RenderData parameter as its source of report data. |
ReportView |
addNewReportView(RenderData data)
Creates a new ReportView object, using the RenderData parameter as its source of report data. |
void |
addNotify()
This method overrides "addNotify" in JComponent, and registers the needed listeners for the SwingReportViewer. |
void |
addReportView(ReportView repView,
boolean isClosable)
Adds a given ReportView to the ReportViewer - this ReportView need not be initialized at this point in time. |
void |
addReportView(ReportView repView)
Adds a given ReportView to the ReportViewer - this ReportView need not be initialized at this point in time. |
void |
addReportViewChangeListener(ReportViewChangeListener rvcl)
Adds an ReportViewChangeListener to the ReportView. |
void |
addStateChangeListener(java.beans.PropertyChangeListener l)
Adds a PropertyChangeListener to the listener list. |
void |
closeAllReportViews()
This method permanently closes and removes all ReportViews currently in the ReportViewer. |
void |
closeReportView(int index)
Permanently closes and removes the ReportView at the given index, 0-based. |
void |
closeReportView(ReportView view)
Permanently closes and disposes the ReportView given as the parameter and removes it from the ReportViewer. |
ReportView |
createReportView(RenderData data)
Creates a report view and initializes it with the data source "data". |
ActionPool |
getActionPool()
Returns the SwingViewer report actions connected to this viewer. |
java.awt.Component |
getComponent()
All public graphical components of the viewer must implement this method, which returns the actual AWT component so that it can be added to containers, etc. |
ReportView |
getCurrentReportView()
Returns the currently visible or selected ReportView object. |
java.lang.String |
getDefaultExportDirectory()
Returns the default directory in that the Java viewer will save the exported files. |
DefaultSetting |
getDefaultSetting(DefaultSetting.Key key)
Returns the setting of the property defined by the key, or null if no value is set. |
java.lang.Throwable |
getLastError()
Returns the last error which occurred in the viewer. |
static java.io.PrintStream |
getLoggingStream()
Returns the PrintStream used by the viewer for log outputs. |
static int |
getMajorVersion()
Returns the number of the "major version" of this SwingReportViewer, that is, for version 7.5, this would return "7". |
static int |
getMinorVersion()
Returns the number of the "minor version" of this SwingReportViewer, that is, for version 7.5, this would return "5". |
int |
getPrinterDefaultFormatHandling()
Returns the printer default format handling. |
ProgressPool |
getProgressPool()
Returns the ProgressPool of the viewer. |
ReportView |
getReportView(int i)
Returns the report view at the given index. |
int |
getReportViewCount()
Returns the number of ReportViews registered and added to this viewer. |
ToolBar |
getToolBar()
Returns the current ToolBar - this tool bar belongs to the currently visible or selected ReportView object. |
static java.lang.String |
getVersion()
Returns the current version of the SwingReportViewer as a String representation, e.g. "7.5". |
ViewerContext |
getViewerContext()
Returns the current ViewerContext for this viewer, which is used for reacting to and handling events occurring in the viewer. |
boolean |
hasGroupTree()
Returns whether the global "hasGroupTree" setting is on or off (by default it is on). |
boolean |
hasStatusBar()
Returns whether the global setting of "hasStatusBar" is on or off (by default it is on). |
void |
removeNotify()
This method overrides "removeNotify" in JComponent, and unregisters the listeners for the SwingReportViewer. |
void |
removeReportViewChangeListener(ReportViewChangeListener rvcl)
Removes an ReportViewChangeListener from the ReportView. |
void |
removeStateChangeListener(java.beans.PropertyChangeListener l)
Removes a PropertyChangeListener from the list of listeners. |
void |
setCurrentReportView(ReportView rv)
Sets which ReportView is currently selected and to be affected by any toolbar actions, etc. |
void |
setCustomPromptEditor(java.lang.String promptName,
CustomPromptEditor editor)
Registers the given CustomPromptEditor for prompts with the given name, case-insensitive. |
void |
setCustomPromptEditor(java.lang.String promptName,
int valueType,
CustomPromptEditor editor)
Registers the given CustomPromptEditor for prompts with the given name and value type,
case-insensitive. |
void |
setDefaultExportDirectory(java.lang.String directory)
Sets the default directory in that the Java viewer will save the exported files. |
void |
setDefaultSetting(DefaultSetting.Key key,
DefaultSetting value)
Applies a setting defined by the given key-value pair. |
void |
setHasGroupTree(boolean hasGroupTree)
Sets all report views to whether or not they are to show a group tree. |
void |
setHasStatusBar(boolean hasStatusBar)
Sets for all report views whether or not they are to show a status bar. |
static void |
setLoggingStream(java.io.PrintStream stream)
Sets the stream to be used for log outputs. |
void |
setPrinterDefaultFormatHandling(int printerDefaultFormatHandling)
Sets the printer default format handling to use. |
void |
setViewerContext(ViewerContext context)
Sets the ViewerContext for this viewer, used for reacting to and handling events which occur in the viewer. |
| Field Detail |
|---|
public static final int PRINTER_USE_DEFAULT_FORMAT_IF_SIMILAR
public static final int PRINTER_USE_REPORT_FORMAT
| Constructor Detail |
|---|
public SwingReportViewer()
public SwingReportViewer(ViewerContext context)
context - ViewerContext object which handles various user actions. Can be null, which causes the default
SwingViewerContext to be used.| Method Detail |
|---|
public void setViewerContext(ViewerContext context)
setViewerContext in interface ReportViewercontext - ViewerContext to use for this viewer. Can not be null.ViewerContextpublic ViewerContext getViewerContext()
SwingViewerContext.
getViewerContext in interface ReportViewerViewerContextpublic void closeAllReportViews()
ReportViewer.addReportView(ReportView, boolean) will result in an IllegalStateException. Instead
simply create a new report view with the same RenderData.
closeAllReportViews in interface ReportViewerpublic void closeReportView(int index)
closeReportView(0)
will close and remove the first ReportView added to the Viewer, closeReportView(1) the second, etc.
This will also close any currently open connections to the ReportView's RenderData object.
Note that this causes the report view to be disposed of - trying to add it back to the viewer
via ReportViewer.addReportView(ReportView, boolean) will result in an IllegalStateException. Instead
simply create a new report view with the same RenderData.
If there is no ReportView at this index, this method will throw a ViewerException.
closeReportView in interface ReportViewerindex - Index of ReportView to close and remove.public void closeReportView(ReportView view)
ReportViewer.addReportView(ReportView, boolean) will result in an IllegalStateException. Instead
simply create a new report view with the same RenderData.
closeReportView in interface ReportViewerview - ReportView to close and remove from the ReportViewerpublic ToolBar getToolBar()
getToolBar in interface ReportViewer
public ReportView addNewReportView(RenderData data,
boolean isClosable)
ReportViewer.closeReportView(int) or ReportViewer.closeAllReportViews().
addNewReportView in interface ReportViewerdata - RenderData object specifying the source of report dataisClosable - Whether the report view is to have a close button
ReportViewer.closeReportView(int),
ReportViewer.closeReportView(ReportView),
ReportViewer.closeAllReportViews()
public void addReportView(ReportView repView,
boolean isClosable)
ReportViewer.closeReportView(int) or ReportViewer.closeAllReportViews().
addReportView in interface ReportViewerrepView - ReportView to addisClosable - Whether the report view is to have a close buttonReportViewer.closeReportView(int),
ReportViewer.closeReportView(ReportView),
ReportViewer.closeAllReportViews()public ReportView addNewReportView(RenderData data)
ReportViewer.closeReportView(int) or ReportViewer.closeAllReportViews(). In this case, it can not be added
back to the Viewer via this method. Instead it must be recreated with the RenderData.ReportViewer.addNewReportView(RenderData, boolean) instead, where you can manually set whether or not the view
is to have a close button.
addNewReportView in interface ReportViewerdata - RenderData object specifying the source of report data
ReportViewer.closeReportView(int),
ReportViewer.closeReportView(ReportView),
ReportViewer.closeAllReportViews(),
ReportViewer.addNewReportView(RenderData, boolean)public ReportView createReportView(RenderData data)
data - RenderData object for the report data
public void addReportView(ReportView repView)
ReportViewer.closeReportView(int) or ReportViewer.closeAllReportViews(). In this case, it can not be added
back to the viewer via this method. Instead it must be recreated with the RenderData.ReportViewer.addReportView(ReportView, boolean) instead, where you can manually set whether or not the view
is to have a close button.
addReportView in interface ReportViewerrepView - ReportView to addReportViewer.closeReportView(int),
ReportViewer.closeReportView(ReportView),
ReportViewer.closeAllReportViews(),
ReportViewer.addReportView(ReportView, boolean)public void removeNotify()
removeNotify in class javax.swing.JComponentJComponent.addNotify()public void addNotify()
addNotify in class javax.swing.JComponentViewerException - If you attempt to place this into a component whose top window is not a
Swing component. getRootPane() must return a component.JComponent.addNotify()public ReportView getCurrentReportView()
getCurrentReportView in interface ReportViewerpublic void setCurrentReportView(ReportView rv)
ReportViewer.getCurrentReportView(). This method makes
sure that the correct report view is set as "current".ReportViewChangeListener of a change in
the currently selected report view.
setCurrentReportView in interface ReportViewerrv - ReportView to give focus to and to set as "current" report view.ReportViewer.getCurrentReportView()public void setHasGroupTree(boolean hasGroupTree)
setHasGroupTree in interface ReportViewerhasGroupTree - Are all report views to show a group tree?public boolean hasGroupTree()
hasGroupTree in interface ReportViewerpublic void setHasStatusBar(boolean hasStatusBar)
setHasStatusBar in interface ReportViewerhasStatusBar - Are all report views to show a status bar?public boolean hasStatusBar()
hasStatusBar in interface ReportViewerpublic static int getMajorVersion()
public static int getMinorVersion()
public static java.lang.String getVersion()
public ActionPool getActionPool()
public java.lang.Throwable getLastError()
public java.awt.Component getComponent()
myFrame.add(viewer.getComponent())
getComponent in interface ViewerComponentpublic void addReportViewChangeListener(ReportViewChangeListener rvcl)
ReportViewChangeListener to the ReportView.
addReportViewChangeListener in interface ReportViewerrvcl - the ReportViewChangeListener to be addedpublic void removeReportViewChangeListener(ReportViewChangeListener rvcl)
ReportViewChangeListener from the ReportView.
removeReportViewChangeListener in interface ReportViewerrvcl - the listener to be removedpublic static java.io.PrintStream getLoggingStream()
public static void setLoggingStream(java.io.PrintStream stream)
stream - PrintStream the viewer is to log to.public ReportView getReportView(int i)
getReportViewCount()-1, the minimum allowed is 0.
getReportView in interface ReportVieweri - Index of report view to fetch.
public int getReportViewCount()
ReportViewer.getReportView(int).
getReportViewCount in interface ReportViewerpublic void addStateChangeListener(java.beans.PropertyChangeListener l)
PropertyChangeListener to the listener list. The listener will
be informed about status changes of all progresses and messages changes
in the StatusBar.
addStateChangeListener in interface ReportViewerl - PropertyChangeListener to add to the list of listenerspublic void removeStateChangeListener(java.beans.PropertyChangeListener l)
PropertyChangeListener from the list of listeners.
removeStateChangeListener in interface ReportViewerl - PropertyChangeListener to remove from the list of listeners.public ProgressPool getProgressPool()
ProgressPool of the viewer. The ProgressPool handles all progresses
of the viewer. You can add listeners to the ProgressPool to watch status changes of
the progresses.
getProgressPool in interface ReportViewerpublic java.lang.String getDefaultExportDirectory()
public void setDefaultExportDirectory(java.lang.String directory)
directory - Default directory used to save the exported files
public void setCustomPromptEditor(java.lang.String promptName,
CustomPromptEditor editor)
setCustomPromptEditor in interface ReportViewerpromptName - name of prompt to register custom prompt editor for, may not be nulleditor - custom prompt editor for prompting certain prompts with
your own components.
public void setCustomPromptEditor(java.lang.String promptName,
int valueType,
CustomPromptEditor editor)
CustomPromptEditor for prompts with the given name and value type,
case-insensitive. Setting null as the editor unregisters any CustomPromptEditor
for the given name. An existing CustomPromptEditor for the given name and value type will be
replaced with the one set with this method.
Depending on the value type of the prompt, your custom prompt editor should return
one of the following types:
setCustomPromptEditor in interface ReportViewerpromptName - name of prompt to register custom prompt editor for, may not be nullvalueType - value type the prompt (with the above name) must have to register the custom prompt editor.editor - custom prompt editor for prompting certain prompts with
your own components.public void setPrinterDefaultFormatHandling(int printerDefaultFormatHandling)
PRINTER_USE_DEFAULT_FORMAT_IF_SIMILAR (default setting): If the printer default format is A4 while the
report page format is Letter, or vice versa, map the paper format to the printer default setting. Note that this may cause
your report to be slightly scaled so that it fits the page format of the client's printer.PRINTER_USE_REPORT_FORMAT: Forces the report paper format setting to be chosen by default when printing. Note
that this can cause parts of your report to be truncated if the printer is not able to print in the format in your report.
printerDefaultFormatHandling - printer default format handling
java.lang.IllegalArgumentException - if the given parameter is none of the constants allowed for this value.getPrinterDefaultFormatHandling(),
PRINTER_USE_DEFAULT_FORMAT_IF_SIMILAR,
PRINTER_USE_REPORT_FORMATpublic int getPrinterDefaultFormatHandling()
setPrinterDefaultFormatHandling(int) for further information.
setPrinterDefaultFormatHandling(int),
PRINTER_USE_DEFAULT_FORMAT_IF_SIMILAR,
PRINTER_USE_REPORT_FORMATpublic DefaultSetting getDefaultSetting(DefaultSetting.Key key)
key - key specifying which setting to return
public void setDefaultSetting(DefaultSetting.Key key,
DefaultSetting value)
key - key specifying which setting to applyvalue - value of the setting to apply
|
i-net Clear Reports | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||