2
GeoGebra - Dynamic Mathematics for Everyone
3
http://www.geogebra.org
5
This file is part of GeoGebra.
7
This program is free software; you can redistribute it and/or modify it
8
under the terms of the GNU General Public License as published by
9
the Free Software Foundation.
12
package geogebra.gui.view.consprotocol;
14
import geogebra.main.Application;
16
import java.awt.Component;
17
import java.awt.Cursor;
18
import java.awt.Dimension;
19
import java.awt.FlowLayout;
20
import java.awt.event.ActionEvent;
21
import java.awt.event.ActionListener;
22
import java.text.DecimalFormat;
23
import java.text.DecimalFormatSymbols;
24
import java.util.Locale;
26
import javax.swing.Box;
27
import javax.swing.BoxLayout;
28
import javax.swing.ImageIcon;
29
import javax.swing.JButton;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JSpinner;
33
import javax.swing.JSpinner.NumberEditor;
34
import javax.swing.SpinnerModel;
35
import javax.swing.SpinnerNumberModel;
36
import javax.swing.Timer;
37
import javax.swing.event.ChangeEvent;
38
import javax.swing.event.ChangeListener;
41
* Navigation buttons for the construction protocol
43
public class ConstructionProtocolNavigation extends JPanel implements ActionListener {
48
private static final long serialVersionUID = 1L;
49
private JButton btFirst, btPrev, btPlay, btNext, btLast, btOpenWindow;
50
private JLabel lbSteps;
51
private JSpinner spDelay;
52
private double playDelay = 2; // in seconds
53
private JPanel playPanel;
55
private Application app;
56
private ConstructionProtocol prot;
57
private boolean showPlayButton = true,
58
showConsProtButton = true;
60
private AutomaticPlayer player;
61
private boolean isPlaying;
64
* Creates a new navigation bar to step through the construction protocol.
65
* @param internalNavigation: true if navigation bar is part of the protocol window
67
public ConstructionProtocolNavigation(ConstructionProtocol prot) {
69
app = prot.getApplication();
72
new SpinnerNumberModel(2, //initial value
76
spDelay = new JSpinner(model);
77
NumberEditor numEdit = new JSpinner.NumberEditor(spDelay, "#.##");
78
DecimalFormat format = numEdit.getFormat();
79
format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
80
spDelay.setEditor(numEdit);
82
lbSteps = new JLabel();
87
public boolean isPlayButtonVisible() {
88
return showPlayButton;
91
public void setPlayButtonVisible(boolean flag) {
92
showPlayButton = flag;
93
playPanel.setVisible(flag);
96
public boolean isConsProtButtonVisible() {
97
return showConsProtButton;
100
public void setConsProtButtonVisible(boolean flag) {
101
showConsProtButton = flag;
102
btOpenWindow.setVisible(flag);
106
* Returns delay between frames of automatic construction protocol
107
* playing in seconds.
110
public double getPlayDelay() {
114
public void setPlayDelay(double delay) {
118
spDelay.setValue(new Double(playDelay));
119
} catch (Exception e) {
120
spDelay.setValue(new Integer((int) Math.round(playDelay)));
125
public void initGUI() {
128
btFirst = new JButton(app.getImageIcon("nav_skipback.png"));
129
btLast = new JButton(app.getImageIcon("nav_skipforward.png"));
130
btPrev = new JButton(app.getImageIcon("nav_rewind.png"));
131
btNext = new JButton(app.getImageIcon("nav_fastforward.png"));
133
btFirst.addActionListener(this);
134
btLast.addActionListener(this);
135
btPrev.addActionListener(this);
136
btNext.addActionListener(this);
138
JPanel leftPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
139
leftPanel.add(btFirst);
140
leftPanel.add(btPrev);
141
leftPanel.add(lbSteps);
142
leftPanel.add(btNext);
143
leftPanel.add(btLast);
145
playPanel = new JPanel();
146
playPanel.setVisible(showPlayButton);
147
playPanel.add(Box.createRigidArea(new Dimension(20,10)));
148
btPlay = new JButton();
149
btPlay.setIcon(new ImageIcon(app.getPlayImage()));
150
btPlay.addActionListener(this);
152
spDelay.addChangeListener(new ChangeListener() {
153
public void stateChanged(ChangeEvent e) {
155
playDelay = Double.parseDouble(spDelay.getValue().toString());
156
} catch (Exception ex) {
162
playPanel.add(btPlay);
163
playPanel.add(spDelay);
164
playPanel.add(new JLabel("s"));
167
btOpenWindow = new JButton();
168
btOpenWindow.setIcon(app.getImageIcon("table.gif"));
169
btOpenWindow.addActionListener(new ActionListener() {
170
public void actionPerformed(ActionEvent e) {
171
app.getGuiManager().showConstructionProtocol();
175
// add panels together to center
176
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
180
add(Box.createRigidArea(new Dimension(20,10)));
183
setPlayDelay(playDelay);
187
public void setLabels() {
189
btPlay.setText(app.getPlain("Play"));
190
if (btOpenWindow != null)
191
btOpenWindow.setToolTipText(app.getPlain("ConstructionProtocol"));
195
* Updates the texts that show the current construction step and
196
* the number of construction steps.
198
public void update() {
199
int currentStep = prot.getCurrentStepNumber();
200
int stepNumber = prot.getLastStepNumber();
201
lbSteps.setText(currentStep + " / " + stepNumber);
205
* Registers this navigation bar at its protocol
206
* to be informed about updates.
208
public void register() {
209
prot.registerNavigationBar(this);
214
* Unregisters this navigation bar from its protocol.
216
public void unregister() {
217
prot.unregisterNavigationBar(this);
220
public void actionPerformed(ActionEvent e) {
221
Object source = e.getSource();
223
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
225
if (source == btFirst) {
228
else if (source == btLast) {
231
else if (source == btPrev) {
234
else if (source == btNext) {
237
else if (source == btPlay) {
239
player.stopAnimation();
241
player = new AutomaticPlayer(playDelay);
242
player.startAnimation();
246
if (prot.isVisible())
247
prot.scrollToConstructionStep();
249
setCursor(Cursor.getDefaultCursor());
252
private void setComponentsEnabled(boolean flag) {
253
Component comps[] = getComponents();
254
for (int i=0; i < comps.length; i++) {
255
comps[i].setEnabled(flag);
257
btPlay.setEnabled(true);
258
lbSteps.setEnabled(true);
262
* Steps through the construction automatically.
264
private class AutomaticPlayer implements ActionListener {
265
private Timer timer; // for animation
268
* Creates a new player to step through the construction
270
* @param delay in seconds between steps
272
public AutomaticPlayer(double delay) {
273
timer = new Timer((int) (delay * 1000), this);
276
public synchronized void startAnimation() {
277
// dispatch events to play button
278
app.startDispatchingEventsTo(btPlay);
280
btPlay.setIcon(new ImageIcon(app.getPauseImage()));
281
btPlay.setText(app.getPlain("Pause"));
282
setComponentsEnabled(false);
285
if (prot.getCurrentStepNumber() == prot.getLastStepNumber()) {
292
public synchronized void stopAnimation() {
295
// unblock application events
296
app.stopDispatchingEvents();
298
btPlay.setIcon(new ImageIcon(app.getPlayImage()));
299
btPlay.setText(app.getPlain("Play"));
300
setComponentsEnabled(true);
301
app.setDefaultCursor();
304
public synchronized void actionPerformed(ActionEvent e) {
306
if (prot.getCurrentStepNumber() == prot.getLastStepNumber()) {
2
GeoGebra - Dynamic Mathematics for Everyone
3
http://www.geogebra.org
5
This file is part of GeoGebra.
7
This program is free software; you can redistribute it and/or modify it
8
under the terms of the GNU General Public License as published by
9
the Free Software Foundation.
12
package geogebra.gui.view.consprotocol;
14
import geogebra.gui.SetLabels;
15
import geogebra.main.Application;
16
import geogebra.main.settings.AbstractSettings;
17
import geogebra.main.settings.ConstructionProtocolSettings;
18
import geogebra.main.settings.SettingListener;
20
import java.awt.Component;
21
import java.awt.Cursor;
22
import java.awt.Dimension;
23
import java.awt.FlowLayout;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26
import java.text.DecimalFormat;
27
import java.text.DecimalFormatSymbols;
28
import java.util.Locale;
30
import javax.swing.Box;
31
import javax.swing.BoxLayout;
32
import javax.swing.ImageIcon;
33
import javax.swing.JButton;
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36
import javax.swing.JSpinner;
37
import javax.swing.SpinnerModel;
38
import javax.swing.SpinnerNumberModel;
39
import javax.swing.Timer;
40
import javax.swing.JSpinner.NumberEditor;
41
import javax.swing.event.ChangeEvent;
42
import javax.swing.event.ChangeListener;
45
* Navigation buttons for the construction protocol
47
public class ConstructionProtocolNavigation extends JPanel implements ActionListener, SettingListener, SetLabels {
52
private static final long serialVersionUID = 1L;
53
private JButton btFirst, btPrev, btPlay, btNext, btLast, btOpenWindow;
54
private JLabel lbSteps;
55
private JSpinner spDelay;
56
private double playDelay = 2; // in seconds
57
private JPanel playPanel;
59
private Application app;
60
private ConstructionProtocolView prot;
61
private boolean showPlayButton = true,
62
showConsProtButton = true;
64
private AutomaticPlayer player;
65
private boolean isPlaying;
68
* Creates a new navigation bar to step through the construction protocol.
69
* @param internalNavigation: true if navigation bar is part of the protocol window
71
public ConstructionProtocolNavigation(ConstructionProtocolView prot) {
73
app = prot.getApplication();
76
new SpinnerNumberModel(2, //initial value
80
spDelay = new JSpinner(model);
81
NumberEditor numEdit = new JSpinner.NumberEditor(spDelay, "#.##");
82
DecimalFormat format = numEdit.getFormat();
83
format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
85
lbSteps = new JLabel();
89
/* //next 3 rows moved into EuclidianDockPanel.loadComponent
90
//because it not neccessary for all Contruction protocol navigation issue
91
ConstructionProtocolSettings cps = app.getSettings().getConstructionProtocol();
93
cps.addListener(this);
97
public boolean isPlayButtonVisible() {
98
return showPlayButton;
101
public void setPlayButtonVisible(boolean flag) {
102
showPlayButton = flag;
103
playPanel.setVisible(flag);
106
public boolean isConsProtButtonVisible() {
107
return showConsProtButton;
110
public void setConsProtButtonVisible(boolean flag) {
111
showConsProtButton = flag;
112
btOpenWindow.setVisible(flag);
116
* Returns delay between frames of automatic construction protocol
117
* playing in seconds.
120
public double getPlayDelay() {
124
public void setPlayDelay(double delay) {
128
spDelay.setValue(new Double(playDelay));
129
} catch (Exception e) {
130
spDelay.setValue(new Integer((int) Math.round(playDelay)));
135
public void initGUI() {
138
btFirst = new JButton(app.getImageIcon("nav_skipback.png"));
139
btLast = new JButton(app.getImageIcon("nav_skipforward.png"));
140
btPrev = new JButton(app.getImageIcon("nav_rewind.png"));
141
btNext = new JButton(app.getImageIcon("nav_fastforward.png"));
143
btFirst.addActionListener(this);
144
btLast.addActionListener(this);
145
btPrev.addActionListener(this);
146
btNext.addActionListener(this);
148
JPanel leftPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
149
leftPanel.add(btFirst);
150
leftPanel.add(btPrev);
151
leftPanel.add(lbSteps);
152
leftPanel.add(btNext);
153
leftPanel.add(btLast);
155
playPanel = new JPanel();
156
playPanel.setVisible(showPlayButton);
157
playPanel.add(Box.createRigidArea(new Dimension(20,10)));
158
btPlay = new JButton();
159
btPlay.setIcon(new ImageIcon(app.getPlayImage()));
160
btPlay.addActionListener(this);
162
spDelay.addChangeListener(new ChangeListener() {
163
public void stateChanged(ChangeEvent e) {
165
playDelay = Double.parseDouble(spDelay.getValue().toString());
166
} catch (Exception ex) {
172
playPanel.add(btPlay);
173
playPanel.add(spDelay);
174
playPanel.add(new JLabel("s"));
177
btOpenWindow = new JButton();
178
btOpenWindow.setIcon(app.getImageIcon("table.gif"));
179
btOpenWindow.addActionListener(new ActionListener() {
180
public void actionPerformed(ActionEvent e) {
181
//app.getGuiManager().showConstructionProtocol();
182
if(!app.getGuiManager().showView(Application.VIEW_CONSTRUCTION_PROTOCOL))
183
app.getGuiManager().setShowView(true, Application.VIEW_CONSTRUCTION_PROTOCOL);
187
// add panels together to center
188
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
192
add(Box.createRigidArea(new Dimension(20,10)));
195
setPlayDelay(playDelay);
199
public void setLabels() {
201
btPlay.setText(app.getPlain("Play"));
202
if (btOpenWindow != null)
203
btOpenWindow.setToolTipText(app.getPlainTooltip("ConstructionProtocol"));
207
* Updates the texts that show the current construction step and
208
* the number of construction steps.
210
public void update() {
211
int currentStep = prot.getCurrentStepNumber();
212
int stepNumber = prot.getLastStepNumber();
213
lbSteps.setText(currentStep + " / " + stepNumber);
217
* Registers this navigation bar at its protocol
218
* to be informed about updates.
220
public void register() {
221
prot.registerNavigationBar(this);
226
* Unregisters this navigation bar from its protocol.
228
public void unregister() {
229
prot.unregisterNavigationBar(this);
232
public void actionPerformed(ActionEvent e) {
233
Object source = e.getSource();
235
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
237
if (source == btFirst) {
240
else if (source == btLast) {
243
else if (source == btPrev) {
246
else if (source == btNext) {
249
else if (source == btPlay) {
251
player.stopAnimation();
253
player = new AutomaticPlayer(playDelay);
254
player.startAnimation();
258
if (prot.isVisible())
259
prot.scrollToConstructionStep();
261
setCursor(Cursor.getDefaultCursor());
264
private void setComponentsEnabled(boolean flag) {
265
Component comps[] = getComponents();
266
for (int i=0; i < comps.length; i++) {
267
comps[i].setEnabled(flag);
269
btPlay.setEnabled(true);
270
lbSteps.setEnabled(true);
274
* Steps through the construction automatically.
276
private class AutomaticPlayer implements ActionListener {
277
private Timer timer; // for animation
280
* Creates a new player to step through the construction
282
* @param delay in seconds between steps
284
public AutomaticPlayer(double delay) {
285
timer = new Timer((int) (delay * 1000), this);
288
public synchronized void startAnimation() {
289
// dispatch events to play button
290
app.startDispatchingEventsTo(btPlay);
292
btPlay.setIcon(new ImageIcon(app.getPauseImage()));
293
btPlay.setText(app.getPlain("Pause"));
294
setComponentsEnabled(false);
297
if (prot.getCurrentStepNumber() == prot.getLastStepNumber()) {
304
public synchronized void stopAnimation() {
307
// unblock application events
308
app.stopDispatchingEvents();
310
btPlay.setIcon(new ImageIcon(app.getPlayImage()));
311
btPlay.setText(app.getPlain("Play"));
312
setComponentsEnabled(true);
313
app.setDefaultCursor();
316
public synchronized void actionPerformed(ActionEvent e) {
318
if (prot.getCurrentStepNumber() == prot.getLastStepNumber()) {
324
public void settingsChanged(AbstractSettings settings) {
325
ConstructionProtocolSettings cps = (ConstructionProtocolSettings)settings;
326
setPlayButtonVisible(cps.showPlayButton());
327
setPlayDelay(cps.getPlayDelay());
328
setConsProtButtonVisible(cps.showConstructionProtocol());