View Javadoc

1   /**
2    * This program is free software: you can redistribute it and/or modify
3    * it under the terms of the GNU General Public License as published by
4    * the Free Software Foundation, version 3.
5    *
6    * This program is distributed in the hope that it will be useful,
7    * but WITHOUT ANY WARRANTY; without even the implied warranty of
8    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9    * GNU General Public License for more details.
10   *
11   * You should have received a copy of the GNU General Public License
12   * along with this program. If not, see <http://www.gnu.org/licenses/>.
13   */
14  
15  package net.curre.prefcount.gui;
16  
17  import java.awt.Graphics;
18  import java.awt.Graphics2D;
19  import java.awt.RenderingHints;
20  import java.awt.print.PageFormat;
21  import java.awt.print.Printable;
22  import java.awt.print.PrinterException;
23  
24  import net.curre.prefcount.PrefCountRegistry;
25  import net.curre.prefcount.gui.theme.skin.PrefSkin;
26  import net.curre.prefcount.gui.theme.skin.PrintSkin;
27  
28  /**
29   * Object of this class represents a score board template.
30   * <p/>
31   * Created date: Jun 22, 2008
32   *
33   * @author Yevgeny Nyden
34   */
35  public class Template implements Printable {
36  
37    /** Number of player for the template. */
38    private final int numberOfPlayers;
39  
40    /**
41     * Creates a new <code>Template</code> object.
42     *
43     * @param numberOfPlayers Number of player for the template.
44     */
45    public Template(int numberOfPlayers) {
46      this.numberOfPlayers = numberOfPlayers;
47    }
48  
49  
50    /** {@inheritDoc} */
51    public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
52      if (pageIndex > 0) {
53        return (NO_SUCH_PAGE);
54  
55      } else {
56        Graphics2D g2 = (Graphics2D) g;
57        g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
58  
59        final int height = (int) pageFormat.getImageableHeight();
60        final int width = (int) pageFormat.getImageableWidth();
61  
62        // drawing the the score board
63        MainWindow mainWindow = PrefCountRegistry.getInstance().getMainWindow();
64        final PrefSkin skin = new PrintSkin();
65  
66        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
67                            RenderingHints.VALUE_ANTIALIAS_ON);
68        mainWindow.scoreBoardPanel.drawScoreBoard(g2, width, height - 20, 0, 20,
69                                                  numberOfPlayers, skin);
70        return (PAGE_EXISTS);
71      }
72    }
73  
74  
75  }