summaryrefslogtreecommitdiffstats
path: root/logo/src/xlogo/kernel/Kernel.java
blob: 2a338411dc7431ab8b7f7d8d8d974e60adac02a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* XLogo4Schools - A Logo Interpreter specialized for use in schools, based on XLogo by Loic Le Coq
 * Copyright (C) 2013 Marko Zivkovic
 * 
 * Contact Information: marko88zivkovic at gmail dot com
 * 
 * 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., 51 Franklin Street, Fifth Floor, Boston, 
 * MA 02110-1301, USA.
 * 
 * 
 * This Java source code belongs to XLogo4Schools, written by Marko Zivkovic
 * during his Bachelor thesis at the computer science department of ETH Zurich,
 * in the year 2013 and/or during future work.
 * 
 * It is a reengineered version of XLogo written by Loic Le Coq, published
 * under the GPL License at http://xlogo.tuxfamily.org/
 * 
 * Contents of this file were initially written by Loic Le Coq,
 * modifications, extensions, refactorings might have been applied by Marko Zivkovic 
 */

package xlogo.kernel;

import java.util.ArrayList;
import java.awt.Color;

import xlogo.kernel.userspace.UserSpace;
import xlogo.storage.user.DrawQuality;
import xlogo.storage.workspace.Language;
/**
 * Title : XLogo
 * Description : XLogo is an interpreter for the Logo
 * programming language
 * 
 * @author Loïc Le Coq
 */
import xlogo.Application;

public class Kernel
{
	protected static long		chrono		= 0;
	
	protected ArrayFlow			flows		= new ArrayFlow();	// Contient les
																// flux de
																// lecture ou
																// d'écriture
																
	protected static boolean	mode_trace	= false;			// true si le
																// mode trace
																// est
																// enclenchée
																// (permet de
																// suivre les
																// procédures)
																
	// interprete the user command and launch primitive and procedure
	private Interprete			interprete;
	// For all drawing operation
	// protected DrawPanel dg;
	// For primitive
	protected Primitive			primitive	= null;
	private UserSpace			userSpace;
	private Application			app;
	private MP3Player			mp3Player;
	private MyCalculator		myCalculator;
	
	public Kernel(Application app, UserSpace userSpace)
	{
		this.app = app;
		this.userSpace = userSpace;
		initCalculator(-1);
	}
	
	public UserSpace getWorkspace()
	{
		return userSpace;
	}
	
	public void setWorkspace(UserSpace workspace)
	{
		userSpace = workspace;
		interprete.setWorkspace(userSpace);
	}
	
	protected String listSearch() throws xlogo.kernel.LogoError
	{
		return interprete.chercheListe();
	}
	
	public void fcfg(Color color)
	{
		app.getDrawPanel().fcfg(color);
	}
	
	public Turtle getActiveTurtle()
	{
		return app.getDrawPanel().tortue;
	}
	
	public MyCalculator getCalculator()
	{
		return myCalculator;
	}
	
	public void fcc(Color color)
	{
		app.getDrawPanel().fcc(color);
	}
	
	public void vide_ecran()
	{
		app.getDrawPanel().videecran();
	}
	
	public void setNumberOfTurtles(int i)
	{
		app.getDrawPanel().setNumberOfTurtles(i);
	}
	
	public void setDrawingQuality(DrawQuality q)
	{
		app.getDrawPanel().setQuality(q);
	}
	
	public Color getScreenBackground()
	{
		return app.getDrawPanel().getBackgroundColor();
	}
	
	public void change_image_tortue(String chemin)
	{
		app.getDrawPanel().change_image_tortue(app, chemin);
	}
	
	public void initGraphics()
	{
		app.getDrawPanel().initGraphics();
	}
	
	public void buildPrimitiveTreemap(Language lang)
	{
		primitive.buildPrimitiveTreemap(lang);
	}
	
	public String execute(StringBuffer st) throws LogoError
	{
		return interprete.execute(st);
	}
	
	protected void initCalculator(int s)
	{
		myCalculator = new MyCalculator(s);
		
	}
	
	public void initPrimitive()
	{
		primitive = new Primitive(app);
	}
	
	public void initInterprete()
	{
		interprete = new Interprete(app);
	}
	
	/**
	 * Returns the InstructionBuffer containing all commands to execute
	 */
	public InstructionBuffer getInstructionBuffer()
	{
		return interprete.getInstructionBuffer();
	}
	
	public void setMp3Player(MP3Player mp3Player)
	{
		this.mp3Player = mp3Player;
	}
	
	public MP3Player getMp3Player()
	{
		return mp3Player;
	}
	
	class ArrayFlow extends ArrayList<MyFlow>
	{
		ArrayFlow()
		{
			super();
		}
		
		private static final long	serialVersionUID	= 1L;
		
		protected int search(int id)
		{
			for (int i = 0; i < size(); i++)
			{
				if (get(i).getId() == id)
					return i;
			}
			return -1;
		}
		
	}
}