Search in sources :

Example 1 with MachineWrapper

use of increment.simulator.userInterface.MachineWrapper in project CSCI-6461-Simulator by lkstc112233.

the class NewMain method start.

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Virtual Machine");
    machine = new MachineWrapper(new Machine());
    mapping = new HashMap<>();
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    for (int j = 0; j < 3; ++j) {
        ColumnConstraints cc = new ColumnConstraints();
        cc.setPercentWidth(100 / 3.);
        grid.getColumnConstraints().add(cc);
    }
    for (int j = 0; j < 6; ++j) {
        RowConstraints cc = new RowConstraints();
        cc.setPercentHeight(100 / 6.);
        grid.getRowConstraints().add(cc);
    }
    grid.setHgap(50);
    grid.setVgap(10);
    grid.setPadding(new Insets(50, 50, 50, 50));
    Scene scene = new Scene(grid, 800, 600);
    primaryStage.setScene(scene);
    grid.add(getBox(grid, "Tick: ", machine.getTickProperty().asString()), 0, 0);
    grid.add(getBox(grid, "PC: ", machine.getProgramCounterProperty()), 0, 1);
    grid.add(getBox(grid, "BUS: ", machine.getBusProperty()), 0, 2);
    grid.add(getBox(grid, "MAR: ", machine.getMemoryAddressRegisterProperty()), 0, 3);
    grid.add(getBox(grid, "MBR: ", machine.getMemoryBufferRegisterProperty()), 0, 4);
    grid.add(getBox(grid, "IR: ", machine.getInstructionRegisterProperty()), 0, 5);
    grid.add(getBox(grid, "GPRF: ", machine.getGeneralPurposeRegisterFileProperty()), 1, 0, 1, 2);
    grid.add(getBox(grid, "IRF: ", machine.getIndexRegisterFileProperty()), 1, 2, 1, 2);
    grid.add(getBox(grid, "Control Unit: ", machine.getControlUnitProperty()), 1, 4);
    grid.add(getScrollBox(grid, "Memory: ", machine.getMemoryProperty()), 2, 0, 1, 6);
    automaticTick = new Timeline(new KeyFrame(Duration.millis(1), new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            machine.tick();
        }
    }));
    automaticTick.setCycleCount(Timeline.INDEFINITE);
    HBox buttons = new HBox();
    buttons.setSpacing(10);
    grid.add(buttons, 0, 6, 3, 1);
    Button btn = new Button("Tick");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            machine.tick();
        }
    });
    buttons.getChildren().add(btn);
    btn = new Button("Auto tick on/off");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            if (Status.RUNNING == automaticTick.getStatus())
                automaticTick.pause();
            else
                automaticTick.play();
        }
    });
    buttons.getChildren().add(btn);
    btn = new Button("Show magic panel");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            getControlPanel().show();
        }
    });
    buttons.getChildren().add(btn);
    btn = new Button("Show front panel");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            getFrontPanel().show();
        }
    });
    buttons.getChildren().add(btn);
    btn = new Button("Show screen panel");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            getScreenPanel().show();
        }
    });
    buttons.getChildren().add(btn);
    scene.getStylesheets().add("/res/css/background.css");
    primaryStage.show();
}
Also used : HBox(javafx.scene.layout.HBox) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) ColumnConstraints(javafx.scene.layout.ColumnConstraints) ActionEvent(javafx.event.ActionEvent) MachineWrapper(increment.simulator.userInterface.MachineWrapper) Scene(javafx.scene.Scene) Machine(increment.simulator.Machine) RowConstraints(javafx.scene.layout.RowConstraints) Timeline(javafx.animation.Timeline) Button(javafx.scene.control.Button) KeyFrame(javafx.animation.KeyFrame)

Aggregations

Machine (increment.simulator.Machine)1 MachineWrapper (increment.simulator.userInterface.MachineWrapper)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1 ActionEvent (javafx.event.ActionEvent)1 Insets (javafx.geometry.Insets)1 Scene (javafx.scene.Scene)1 Button (javafx.scene.control.Button)1 ColumnConstraints (javafx.scene.layout.ColumnConstraints)1 GridPane (javafx.scene.layout.GridPane)1 HBox (javafx.scene.layout.HBox)1 RowConstraints (javafx.scene.layout.RowConstraints)1