1 | /* |
2 | * Copyright (c) 2005 The PseudoQ Project. |
3 | * |
4 | * This file is part of PseudoQ. |
5 | * |
6 | * PseudoQ is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU Lesser General Public License as published by |
8 | * the Free Software Foundation; either version 2.1 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * PseudoQ is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public License |
17 | * along with PseudoQ; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | */ |
20 | |
21 | package net.sourceforge.pseudoq.gui; |
22 | |
23 | import net.sourceforge.pseudoq.model.PuzzleTypeEnum; |
24 | |
25 | /** |
26 | * Factory class for GridPainter instances. |
27 | * @author <a href="http://sourceforge.net/users/stevensa">Andrew Stevens</a> |
28 | */ |
29 | public class GridPainterFactory { |
30 | /** Log4J logger */ |
31 | private static final org.apache.log4j.Logger log = |
32 | org.apache.log4j.LogManager.getLogger(GridPainterFactory.class); |
33 | |
34 | /** Prevent instantiation as all methods are static. */ |
35 | private GridPainterFactory() { |
36 | } |
37 | |
38 | /** |
39 | * Create a new GridPainter instance for the specified puzzle type. The |
40 | * actual implementation class returned will depend on the type. |
41 | * @param type The puzzle type. |
42 | * @return An initialised painter, or null if the puzzle type is unknown |
43 | * to the factory. |
44 | */ |
45 | public static GridPainter newInstance(PuzzleTypeEnum type) { |
46 | GridPainter painter = null; |
47 | |
48 | switch (type) { |
49 | case TINY: |
50 | painter = new TinyGridPainter(); |
51 | break; |
52 | case MINI: |
53 | painter = new MiniGridPainter(); |
54 | break; |
55 | case MINI_X: |
56 | painter = new MiniXGridPainter(); |
57 | break; |
58 | case SMALL_X: |
59 | painter = new SmallXGridPainter(); |
60 | break; |
61 | case STANDARD: |
62 | painter = new StandardGridPainter(); |
63 | break; |
64 | case SUPER: |
65 | painter = new SuperGridPainter(); |
66 | break; |
67 | case LARGE: |
68 | painter = new LargeGridPainter(); |
69 | break; |
70 | case STANDARD_SAMURAI: |
71 | painter = new SamuraiGridPainter(); |
72 | break; |
73 | default: |
74 | log.error("Unknown puzzle type"); |
75 | // return null |
76 | break; |
77 | } |
78 | |
79 | return painter; |
80 | } |
81 | |
82 | } |