2 * Sudokuki - essential sudoku game
3 * Copyright (C) 2007-2016 Sylvain Vedrenne
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.jankenpoi.sudokuki.controller;
20 import java.util.ArrayList;
21 import java.util.List;
23 import net.jankenpoi.sudokuki.model.GridChangedEvent;
24 import net.jankenpoi.sudokuki.model.GridModel;
25 import net.jankenpoi.sudokuki.model.GridModel.GridValidity;
26 import net.jankenpoi.sudokuki.view.GridView;
28 public class GridController {
30 private GridModel model;
32 List<GridView> views = new ArrayList<GridView>();
34 public GridController(GridModel model) {
38 public void displayViews() {
39 for (GridView view : views) {
44 public void closeViews() {
45 for (GridView view : views) {
50 public void notifyGridChanged() {
51 model.fireGridChanged(new GridChangedEvent(model, 0, 0, (short)0));
54 public void notifyGridValueChanged(int li, int co, int value, boolean silent) {
55 model.setCellValue(li, co, value, silent);
58 public void notifyGridMemosChanged(int li, int co, byte[] memos) {
59 model.clearCellMemos(li, co);
60 model.setCellMemos(li, co, memos);
63 public void addView(GridView view) {
65 view.setController(this);
66 view.gridChanged(new GridChangedEvent(model, 0, 0, (short)0));
67 model.addGridListener(view);
71 public void notifySetAllMemosRequested() {
72 model.setMemosForAllCells();
75 public void notifyClearAllMovesRequested() {
76 model.clearAllUserMoves();
79 public void notifyClearAllMemosRequested() {
80 model.clearAllUserMemos();
83 public void notifyEnterCustomGridMode() {
84 model.enterCustomGridMode();
87 public void notifyExitCustomGridModeRequested() {
88 GridValidity validity = model.getGridValidity();
89 if (validity.isGridValid()) {
90 model.exitCustomGridMode();
92 model.fireGridChanged(new GridChangedEvent(model, 0, 0, (short)0));
95 public void notifyNewGridRequested() {
96 if (model.getCustomGridMode()) {
97 model.exitCustomGridMode();
99 model.requestNewGrid();
100 model.fireGridChanged(new GridChangedEvent(model, 0, 0, (short)0));
103 public void notifyResetGridFromShorts(short[] externalCellInfos) {
104 if (model.getCustomGridMode()) {
105 model.exitCustomGridMode();
107 model.resetGridModelFromShorts(externalCellInfos);
108 model.fireGridChanged(new GridChangedEvent(model, 0, 0, (short)0));
111 public int[] getCellInfosFromModel() {
112 return model.asIntArray();
115 public void notifyGridResolutionSuccess() {
117 model.setGridResolved();
120 public void notifyGridComplete() {
122 model.setGridComplete();
125 private int lastLI = 4;
126 private int lastCO = 4;
128 public void notifyFocusPositionChanged(int li, int co) {
133 public void notifySetMemosHere() {
134 model.setMemosForThisCell(lastLI, lastCO);