// BlogBridge -- RSS feed reader, manager, and web based service
// Copyright (C) 2002-2007 by R. Pito Salas
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software Foundation;
// either version 2 of the License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with this program;
// if not, write to the Free Software Foundation, Inc., 59 Temple Place,
// Suite 330, Boston, MA 02111-1307 USA
//
// Contact: R. Pito Salas
// mailto:pitosalas@users.sourceforge.net
// More information: about BlogBridge
// http://www.blogbridge.com
// http://sourceforge.net/projects/blogbridge
//
// $Id: ArticlesByDayReport.java,v 1.4 2007/10/03 12:32:29 spyromus Exp $
//
package com.salas.bb.reports;
import com.jgoodies.forms.layout.CellConstraints;
import com.salas.bb.persistence.domain.CountStats;
import com.salas.bb.utils.i18n.Strings;
import com.salas.bb.utils.uif.BBFormBuilder;
import com.salas.bb.utils.uif.charts.LineChart;
import com.salas.bb.utils.uif.charts.LineChartConfig;
import com.salas.bb.utils.uif.charts.LineChartData;
import javax.swing.*;
import java.awt.*;
import java.text.DateFormatSymbols;
import java.util.Calendar;
/**
* Report on articles read by day of a week.
*/
class ArticlesByDayReport extends AbstractReport
{
// --- Initialized by initializeData() ------------------------------------
/** Number of articles read broken by day (total). */
private int[] readByDayTotal;
/** Number of articles read broken by day (since reset). */
private int[] readByDayReset;
/**
* Returns the report name.
*
* @return name.
*/
public String getReportName()
{
return Strings.message("report.articles.read.by.day");
}
/**
* Initializes data for the view.
*
* @param provider report data provider.
*/
protected void doInitializeData(IReportDataProvider provider)
{
// Do processing
readByDayReset = new int[7];
readByDayTotal = new int[7];
CountStats[] perDay = provider.statGetItemsReadPerWeekday();
for (int i = 0; i < 7; i++)
{
if (perDay == null)
{
readByDayReset[i] = readByDayTotal[i] = 0;
} else
{
readByDayReset[i] = (int)perDay[i].getCountReset();
readByDayTotal[i] = (int)perDay[i].getCountTotal();
}
}
}
/** Prepares the view for the display. Should be called after the initializeData() method. */
protected void doLayoutView()
{
// Initialize data by day
String[] days = new String[7];
DateFormatSymbols dfs = new DateFormatSymbols();
for (int i = 0; i < 7; i++) days[i] = dfs.getWeekdays()[Calendar.SUNDAY + i];
LineChartConfig config = new LineChartConfig();
LineChartData dataByDay = new LineChartData(readByDayTotal, days);
LineChart chartByDay = new LineChart(dataByDay, config);
LineChartData dataByDayReset = new LineChartData(readByDayReset, days);
LineChart chartByDayReset = new LineChart(dataByDayReset, config);
// Initialize the panel itself
setBackground(config.getBackgroundColor());
// Build the layout
BBFormBuilder builder = new BBFormBuilder("p:grow", this);
builder.setDefaultDialogBorder();
JLabel lbByDay = new JLabel(Strings.message("report.articles.read.by.day.title"));
Font fntBold = lbByDay.getFont().deriveFont(Font.BOLD);
lbByDay.setFont(fntBold);
builder.append(lbByDay, 1, CellConstraints.CENTER, CellConstraints.DEFAULT);
builder.appendRelatedComponentsGapRow(2);
builder.appendRow("p:grow");
builder.append(chartByDay, 1, CellConstraints.FILL, CellConstraints.FILL);
builder.appendUnrelatedComponentsGapRow(2);
JLabel lbByDayReset = new JLabel(Strings.message("report.articles.read.by.day.title") + " " +
Strings.message("report.since.reset.box"));
lbByDayReset.setFont(fntBold);
builder.append(lbByDayReset, 1, CellConstraints.CENTER, CellConstraints.DEFAULT);
builder.appendRelatedComponentsGapRow(2);
builder.appendRow("p:grow");
builder.append(chartByDayReset, 1, CellConstraints.FILL, CellConstraints.FILL);
}
}