Search in sources :

Example 1 with CbmFile

use of se.light.assembly64.d64.CbmFile in project assembly64fx by freabemania.

the class C64ImageController method init.

public void init(File file, boolean launchExplorerEvenIfOnlyOneFile, boolean loadStar) throws Exception {
    try {
        viceService = ViceService.getInstance();
        this.diskImage = DiskImage.getDiskImage(file.getAbsolutePath());
        this.file = file;
        if (loadStar) {
            super.setCancelShow(true);
            launchVice("*");
            return;
        }
        diskImage.readDirectory();
        diskImage.readBAM();
        if (!launchExplorerEvenIfOnlyOneFile) {
            int ctr = 0;
            for (int fileNum = 0; fileNum <= diskImage.getFilenumberMax() - 1; fileNum++) {
                CbmFile f = diskImage.getCbmFile(fileNum);
                if (getFileTypeString(f.getFileType()).equals("PRG")) {
                    ctr++;
                }
            }
            if (ctr == 1) {
                super.setCancelShow(true);
                launchVice("*");
                return;
            }
        }
        left.setFont(Font.loadFont(getClass().getResourceAsStream(C64_TTF), 16));
        center.setFont(Font.loadFont(getClass().getResourceAsStream(C64_TTF), 16));
        right.setFont(Font.loadFont(getClass().getResourceAsStream(C64_TTF), 16));
        center.setText(getTextStr("\"" + StringUtils.rightPad(diskImage.getBam().getDiskName(), 16) + "\"" + StringUtils.leftPad(diskImage.getBam().getDiskId(), 6)));
        left.setText("0");
        left.setDisable(true);
        center.setDisable(true);
        right.setDisable(true);
        List<Text> items2 = new ArrayList<>();
        for (int fileNum = 0; fileNum <= diskImage.getFilenumberMax() - 1; fileNum++) {
            CbmFile f = diskImage.getCbmFile(fileNum);
            String content = StringUtils.rightPad(String.valueOf(f.getSizeInBlocks()), 4);
            content += "\"";
            content += f.getName() + "\"" + getTabs(f.getName());
            content += getFileTypeString(f.getFileType());
            items2.add(getText(content));
        }
        items2.add(getText(diskImage.getBlocksFree() + " BLOCKS FREE."));
        ObservableList<Text> tmp = FXCollections.observableArrayList(items2);
        items.setItems(tmp);
        items.getSelectionModel().select(0);
        items.setOnMouseClicked((event) -> {
            if (event.getClickCount() == 2) {
                launchVice(diskImage.getCbmFile(items.getSelectionModel().getSelectedIndex()).getName());
            }
            ;
        });
        items.setOnKeyTyped((event) -> launchVice(diskImage.getCbmFile(items.getSelectionModel().getSelectedIndex()).getName()));
        items.setOnKeyReleased((event) -> {
            if (items.getSelectionModel().getSelectedIndex() == diskImage.getFilenumberMax()) {
                items.getSelectionModel().select(diskImage.getFilenumberMax() - 1);
            }
        });
        final ContextMenu contextMenu = new ContextMenu();
        MenuItem loadStarMenuItem = new MenuItem("LOAD\"*\",8,1");
        loadStarMenuItem.setOnAction((ActionEvent event2) -> {
            launchVice("*");
        });
        contextMenu.getItems().add(loadStarMenuItem);
        items.setContextMenu(contextMenu);
        Analytics.sendEvent("imagebrowser", "open_image");
    } catch (Exception e) {
        GenericMessageDialogController.withErrorProps("Error", "Unable to open image").showAndWait();
        throw e;
    }
}
Also used : ActionEvent(javafx.event.ActionEvent) CbmFile(se.light.assembly64.d64.CbmFile) ArrayList(java.util.ArrayList) Text(javafx.scene.text.Text) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem)

Aggregations

ArrayList (java.util.ArrayList)1 ActionEvent (javafx.event.ActionEvent)1 ContextMenu (javafx.scene.control.ContextMenu)1 MenuItem (javafx.scene.control.MenuItem)1 Text (javafx.scene.text.Text)1 CbmFile (se.light.assembly64.d64.CbmFile)1