Product How-To: Customizing a Report with Presenters

The presenter is a powerful concept that allows unlimited extensibility of InetSoft products for customizing reports by providing any user-defined rendering of any object value. It has a very simple set of methods, which are defined in the inetsoft.report.Presenter interface. See the API JavaDoc for the details.

The InetSoft package comes with two presenters that display a numeric value as a horizontal bar. In this example we build a slightly different bar presenter. Instead of a bar growing from left to right, we write a presenter to have bars growing from right to left.

We first define a few constructors, a default constructor and a constructor that takes a maximum value and color as parameters. The maximum value is used to calculate the size of the bar. The size is the proportion of the actual value to the maximum value.

public class RBarPresenter implements Presenter {
   public RBarPresenter() {
   }
   public RBarPresenter(double max, Color color) {
      this.max = max;
      this.color = color;
   }
report presenter example

Pick a default size for the bar presenter and allow the size to be changed by users:

public Dimension getPreferredSize(Object v) {

   return psize;
}

public void setPreferredSize(Dimension psize) {
   psize = new Dimension(psize);
}

We also need to define the isPresenterOf() method to check if a type of object can be presented by this presenter. This is used when a presenter is assigned to a table column to avoid using it on the wrong types of objects, if there is more than one type in the column.

public boolean isPresenterOf(Class type) {
   return Number.class.isAssignableFrom(type);
}

Last, we define the paint() method for actually painting the bar. We can calculate the width of the bar using the value passed into paint() and the maximum value and presenter area width. Then we align the bar to the right of the area and paint.

public void paint(Graphics g, Object v, int x, int y, int w, int h) {
   if(v != null && v instanceof Number) {
      Rectangle clip = g.getClipBounds();
      Color oc = g.getColor();
      g.setClip(x, y, w, h);
      double n = ((Number) v).doubleValue();
      g.setColor(color);
      int width = (int) (n * w / max);
      g.fillRect(x+w-width, y+2, width, h-4);
      g.setColor(oc);
      g.setClip(clip);
   }
}

Customized Report Summary

We have discussed the API behind the table report element. We followed this with a description of the various table lens classes, which adapt data so that it is correctly formatted for the InetSoft table report element. This was followed by a description of the Transformer classes, which are used to project different views onto other table lens classes. We concluded by describing some advanced formatting capabilities such as object presenters, which display graphic representations of numeric data.

More Articles About Reporting

Adding Contextual Information to Your Data Visualization - So I can see how visualization could be very useful in systems management if you're trying to understand how very complex systems are performing or not performing. I am guessing that's a pretty key area for data visualization. We've all seen these kinds of systems management software. We see peaks in valleys and you can see kind of how their operations are running. What are some other interesting ways to visualize...

Evaluate InetSoft's Dashboard Builder for Salesforce - Are you looking for a good dashboard builder for salesforce? InetSoft's pioneering dashboard reporting application produces great-looking web-based dashboards with an easy-to-use drag-and-drop designer. Get cloud-flexibility for your deployment. Minimize costs with a small-footprint solution. Maximize self-service for all types of users. No dedicated BI developer required. View a demo and try interactive examples...

Executable Reports Introduction - The replet is the central concept of InetSoft's server-based active reporting model. A replet is an executable report. It can be parameterized to produce different types of reports. Because a replet can produce completely different reports based on parameter values, it is possible for a reporting system to use only one replet to produce all reports. Obviously, this is not the recommended approach. However, this flexibility enables a replet to represent a family of reports which share a common presentation and business logic code...

Exploration or Visualization Tool - And when you look at these BI vendors, the other thing is that they see this as an addition to your environment. You have reporting and dashboards, and on top of it you get this exploration tool or this visualization tool which you add to that environment. To some extent you do want that. But the reality is that the interfaces and the expectation of users are morphing. Phones, apps, and websites, all these things are changing the expectation...

Models of Neurons - In this article in the continuation of the educational series on machine learning, I am going to describe some relatively simple models of neurons. I will describe a number of different models starting with simple linear and threshold neurons and then describing slightly more complicated models. These are much simpler than real neurons, but they are still complicated enough to allow us to make neural nets to do some very interesting kinds of machine learning...

Need Data Discovery Software - There was a report on data discovery and UIA recently so I will enumerate some of the issues that came up in that. So I think you know this current observation. Probably no one would dispute this, but I think one of the big things going on in BI and analytics right now is the idea that we're moving from a time when the focus has been on getting the data in and storing the data. Certainly all those issues are very important, and we could devote many, many webinars to those issues, but really I think most organizations are focused on getting information into the workplace, putting it to work...

No Power Users Are Available - So what I'd like to talk to you now is integration on the quality side I think is very important, but I'd like to just give you a feel for what kinds of things you do with it, we talked about the specific examples of what these people did, but how do you understand the scope of what you're dealing? The way that we understand the scope of what we are dealing with is through what we call the click paradigm. So for example, you may have a situation where you got a number of power users. They understand how to do analysis. They are looking for answers to specific questions...

Report Application Development Tools - InetSoft BI products include a number of tools for report application development. We will examine the major BI functions and features in this section, describing their core capabilities. Available in Style Report and Style Intelligence products, the Designer allows for the creation of dashboard and report templates. A report template represents the markup describing the layout of a report. Using the intuitive visual GUI interface, developing reports is a process of setting up a page layout and placing elements, such as text, charts, sections, or tables on the template...

Previous: Report Programming - Table Transformer