summaryrefslogtreecommitdiff
path: root/src/main/java/testing/HeadlessSimulatorFrame.java
blob: 8c85b0b75dadae6436b5871bb8ff6ed96c5a2c34 (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
package testing;

import simulator.*;
import prefs.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;

/**
 * A headless implementation of VSSimulatorFrame that avoids GUI initialization.
 * This frame is used for loading simulations in test/headless environments.
 */
public class HeadlessSimulatorFrame {
    private Vector<VSSimulator> simulators = new Vector<>();
    private VSPrefs prefs;
    private VSSimulator currentSimulator;
    
    public HeadlessSimulatorFrame(VSPrefs prefs) {
        this.prefs = prefs;
    }
    
    public void addSimulator(VSSimulator simulator) {
        simulators.add(simulator);
        currentSimulator = simulator;
    }
    
    public void removeSimulator(VSSimulator simulator) {
        simulators.remove(simulator);
        if (currentSimulator == simulator) {
            currentSimulator = simulators.isEmpty() ? null : simulators.lastElement();
        }
    }
    
    public void resetCurrentSimulator() {
        if (currentSimulator != null) {
            simulators.remove(currentSimulator);
            currentSimulator = null;
        }
    }
    
    public VSPrefs getPrefs() {
        return prefs;
    }
    
    public Vector<VSSimulator> getSimulators() {
        return simulators;
    }
    
    public VSSimulator getCurrentSimulator() {
        return currentSimulator;
    }
    
    public void setVisible(boolean visible) {
        // Do nothing - no GUI to show
    }
    
    public void pack() {
        // Do nothing - no GUI to pack
    }
    
    public void repaint() {
        // Do nothing - no GUI to repaint
    }
    
    public boolean isDisplayable() {
        return false;
    }
    
    public void dispose() {
        simulators.clear();
        currentSimulator = null;
    }
}