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

import simulator.VSSimulatorFrame;
import prefs.VSPrefs;
import javax.swing.SwingUtilities;
import java.awt.Dimension;
import java.awt.Point;

/**
 * A minimal simulator frame for headless operation.
 * Creates a real frame but immediately hides it and moves it off-screen.
 */
public class DummySimulatorFrame extends VSSimulatorFrame {
    
    public DummySimulatorFrame(VSPrefs prefs) {
        super(prefs, null);  // null for relativeTo component
        
        // Make the frame as small as possible and move off-screen
        SwingUtilities.invokeLater(() -> {
            setSize(1, 1);
            setLocation(-1000, -1000);
            setVisible(false);
        });
    }
    
    @Override
    public void resetCurrentSimulator() {
        // Check if we have a current simulator before resetting
        if (getCurrentSimulator() != null) {
            // Only reset menu states, don't update GUI
            getCurrentSimulator().getMenuItemStates().setStart(true);
            getCurrentSimulator().getMenuItemStates().setPause(false);
            getCurrentSimulator().getMenuItemStates().setReset(false);
            getCurrentSimulator().getMenuItemStates().setReplay(false);
        }
    }
    
    @Override
    public void updateSimulatorMenu() {
        // Do nothing - no menu updates in headless mode
    }
    
    @Override
    public void setVisible(boolean visible) {
        // Always keep invisible
        super.setVisible(false);
    }
    
    @Override
    public void pack() {
        // Set minimal size instead of packing
        setSize(1, 1);
    }
    
    @Override
    public void toFront() {
        // Do nothing - don't bring to front
    }
    
    @Override
    public void repaint() {
        // Do nothing - no repainting needed
    }
    
    @Override
    public void addSimulator(simulator.VSSimulator simulator) {
        // Add simulator without triggering tab changes and painting
        if (getSimulators() != null) {
            getSimulators().add(simulator);
        }
        setCurrentSimulator(simulator);
    }
    
    protected void setCurrentSimulator(simulator.VSSimulator simulator) {
        try {
            java.lang.reflect.Field field = VSSimulatorFrame.class.getDeclaredField("currentSimulator");
            field.setAccessible(true);
            field.set(this, simulator);
        } catch (Exception e) {
            // Ignore errors
        }
    }
    
    protected java.util.Vector<simulator.VSSimulator> getSimulators() {
        try {
            java.lang.reflect.Field field = VSSimulatorFrame.class.getDeclaredField("simulators");
            field.setAccessible(true);
            return (java.util.Vector<simulator.VSSimulator>) field.get(this);
        } catch (Exception e) {
            return null;
        }
    }
}