home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / tvbrowser / TvBrowser_1.0.exe / plugins / PrintPlugin.jar / printplugin / ChannelPageRenderer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-09-19  |  2.4 KB  |  60 lines

  1. package printplugin;
  2.  
  3. import java.awt.Font;
  4. import java.awt.print.PageFormat;
  5.  
  6. public class ChannelPageRenderer implements PageRenderer {
  7.    static int COLUMN_WIDTH = 180;
  8.    private PageFormat mPageFormat;
  9.    private int mColumnsPerPage;
  10.    private int mStartHour;
  11.    private int mEndHour;
  12.    private ProgramIconSettings mProgramIconSettings;
  13.    public static final Font HEADER_FONT = new Font("Dialog", 1, 32);
  14.    public static final Font FOOTER_FONT = new Font("Dialog", 2, 6);
  15.    public static final Font COL_HEADER_FONT = new Font("Dialog", 1, 18);
  16.  
  17.    public ChannelPageRenderer(PageFormat pageFormat, int columnsPerPage, int startHour, int endHour, ProgramIconSettings programIconSettings) {
  18.       this.mPageFormat = pageFormat;
  19.       this.mColumnsPerPage = columnsPerPage;
  20.       this.mProgramIconSettings = programIconSettings;
  21.       this.mStartHour = startHour;
  22.       this.mEndHour = endHour;
  23.    }
  24.  
  25.    private ColumnModel[] getColumns(PageModel model, int fromInx, int cnt) {
  26.       ColumnModel[] result = new ColumnModel[cnt];
  27.  
  28.       for(int i = fromInx; i < fromInx + cnt; ++i) {
  29.          result[i - fromInx] = model.getColumnAt(i);
  30.       }
  31.  
  32.       return result;
  33.    }
  34.  
  35.    public Page[] createPages(PageModel model) {
  36.       int colCnt = model.getColumnCount();
  37.       int numberOfPages;
  38.       if (colCnt == 0) {
  39.          numberOfPages = 0;
  40.       } else {
  41.          numberOfPages = (colCnt - 1) / this.mColumnsPerPage + 1;
  42.       }
  43.  
  44.       Page[] result = new Page[numberOfPages];
  45.  
  46.       for(int i = 0; i < result.length; ++i) {
  47.          int fromInx = i * this.mColumnsPerPage;
  48.          int inxCnt = this.mColumnsPerPage;
  49.          if (fromInx + inxCnt > colCnt) {
  50.             inxCnt = colCnt - fromInx;
  51.          }
  52.  
  53.          ColumnModel[] cols = this.getColumns(model, fromInx, inxCnt);
  54.          result[i] = new ChannelPage(this, cols, this.mPageFormat, this.mColumnsPerPage, model.getHeader(), model.getFooter(), this.mStartHour, this.mEndHour, this.mProgramIconSettings);
  55.       }
  56.  
  57.       return result;
  58.    }
  59. }
  60.