Search in sources :

Example 1 with Machine

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

the class Main method start.

@Override
public void start(Stage primaryStage) throws Exception {
    Font.loadFont(getClass().getResource("/res/font/Menlo.ttf").toExternalForm(), 10);
    machine = new MachineWrapper(new Machine());
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/res/fxml/FrontPanel.fxml"));
    Parent root = fxmlLoader.load();
    fxmlLoader.<FrontPanelController>getController().setMachine(machine);
    FrontPanelController controller = fxmlLoader.getController();
    Scene scene = new Scene(root);
    scene.getStylesheets().add("/res/css/background.css");
    primaryStage.setScene(scene);
    primaryStage.setTitle("CSCI 6461 Simulator Front Panel");
    primaryStage.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent keyEvent) {
            controller.keyHandler(keyEvent);
            System.out.println(keyEvent.getCode());
            primaryStage.getScene().setOnKeyReleased(event -> {
            });
        }
    });
    primaryStage.show();
}
Also used : KeyEvent(javafx.scene.input.KeyEvent) Application(javafx.application.Application) EventHandler(javafx.event.EventHandler) Parent(javafx.scene.Parent) Scene(javafx.scene.Scene) Stage(javafx.stage.Stage) FXMLLoader(javafx.fxml.FXMLLoader) Font(javafx.scene.text.Font) Machine(increment.simulator.Machine) KeyEvent(javafx.scene.input.KeyEvent) Parent(javafx.scene.Parent) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) Machine(increment.simulator.Machine)

Example 2 with Machine

use of increment.simulator.Machine 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)2 Scene (javafx.scene.Scene)2 MachineWrapper (increment.simulator.userInterface.MachineWrapper)1 KeyFrame (javafx.animation.KeyFrame)1 Timeline (javafx.animation.Timeline)1 Application (javafx.application.Application)1 ActionEvent (javafx.event.ActionEvent)1 EventHandler (javafx.event.EventHandler)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Insets (javafx.geometry.Insets)1 Parent (javafx.scene.Parent)1 Button (javafx.scene.control.Button)1 KeyEvent (javafx.scene.input.KeyEvent)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 Font (javafx.scene.text.Font)1 Stage (javafx.stage.Stage)1