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 package ffx.ui;
39
40 import ffx.potential.MolecularAssembly;
41 import java.awt.event.ActionEvent;
42 import java.awt.event.ActionListener;
43 import javax.swing.Timer;
44
45
46
47
48
49
50 public class Trajectory implements ActionListener {
51
52 private MolecularAssembly molecularSystem;
53 private MainPanel mainPanel;
54 private Timer timer;
55 private int delay = 50;
56 private int desiredspeed = 20;
57 private int cycle = 1;
58 private int sign = 1;
59 private int skip = 1;
60 private boolean oscillate = false;
61
62
63
64
65
66
67
68 public Trajectory(MolecularAssembly mol, MainPanel f) {
69 molecularSystem = mol;
70 mainPanel = f;
71 timer = new Timer(delay, this);
72 timer.setCoalesce(true);
73 }
74
75
76 public void actionPerformed(ActionEvent e) {
77 if (mainPanel.getGraphics3D().isCacheFull()) {
78 return;
79 }
80 cycle = advance(skip * sign);
81 setFrame(cycle);
82 }
83
84
85
86
87
88
89 public MolecularAssembly getFSystem() {
90 return molecularSystem;
91 }
92
93
94
95
96
97
98 public int getFrame() {
99 return molecularSystem.getCurrentCycle();
100 }
101
102
103
104
105
106
107 public void setFrame(int f) {
108 if (molecularSystem != null) {
109 molecularSystem.setCurrentCycle(f);
110 mainPanel.getGraphics3D().updateScene(molecularSystem, true, false, null, false, null);
111 mainPanel.getHierarchy().updateStatus();
112 }
113 }
114
115
116
117
118
119
120 public boolean getOscillate() {
121 return oscillate;
122 }
123
124
125
126
127
128
129 void setOscillate(boolean o) {
130 oscillate = o;
131 }
132
133
134
135
136
137
138 public int getRate() {
139 return desiredspeed;
140 }
141
142
143
144
145
146
147 public void setRate(int s) {
148 if (s > 0 && s <= 100) {
149 desiredspeed = s;
150 delay = 1000 / s;
151 timer.setDelay(delay);
152 }
153 }
154
155
156 public void start() {
157 timer.start();
158 }
159
160
161 public void stop() {
162 timer.stop();
163 }
164
165 private int advance(int adv) {
166 if (molecularSystem != null) {
167 cycle = molecularSystem.getCurrentCycle();
168 int frame = cycle + adv;
169 if ((frame) <= 0) {
170 sign = 1;
171 if (oscillate) {
172 frame = -adv - cycle;
173 } else {
174 frame = molecularSystem.getCycles() + (adv + cycle);
175 }
176 } else if ((frame) > molecularSystem.getCycles()) {
177 if (oscillate) {
178 frame = molecularSystem.getCycles() + (-adv + cycle);
179 sign = -1;
180 } else {
181 sign = 1;
182 frame = cycle - molecularSystem.getCycles() + adv;
183 }
184 }
185 return frame;
186 }
187 return 0;
188 }
189
190
191 void back() {
192 setFrame(getFrame() - 1);
193 }
194
195
196 void forward() {
197 setFrame(getFrame() + 1);
198 }
199
200
201
202
203
204
205 int getSkip() {
206 return skip;
207 }
208
209
210
211
212
213
214 void setSkip(int s) {
215 if (s < 1) {
216 return;
217 }
218 skip = s % molecularSystem.getAtomList().size();
219 }
220
221
222 void rewind() {
223 setFrame(1);
224 }
225 }