Search in sources :

Example 1 with ViceService

use of se.light.assembly64.service.ViceService in project assembly64fx by freabemania.

the class SearchViewFilesController method init.

public void init(SearchResultItem searchedItem, ContentEntryInfo contentEntry, boolean fromSearch) {
    localDb = LocalDBService.getInstance();
    downloadService = DownloadArtifactsService.getInstance();
    playlistService = PlaylistService.getInstance();
    viceService = ViceService.getInstance();
    userService = UserService.getInstance();
    this.fromSearch = fromSearch;
    ReturningTask<Void> task = () -> {
        MetadataService metaDataSercice = MetadataService.getInstance();
        metadata = metaDataSercice.resolve(searchedItem);
        if (metadata.getUrl() == null) {
            toSourceButton.setVisible(false);
        }
        Platform.runLater(() -> {
            if (isNotEmpty(metadata.getEvent()) && isNotEmpty(metadata.getEventType())) {
                eventName.setText(capitalize(metadata.getEvent()));
                eventType.setText(capitalize(metadata.getEventType()));
                showEventName();
            }
            if (isNotEmpty(metadata.getReleaseDate())) {
                date.setText(metadata.getReleaseDate());
                showDate();
            }
            if (isNotEmpty(metadata.getName())) {
                releaseName.setText(capitalize(metadata.getName()));
                showReleaseName();
            }
            if (isNotEmpty(metadata.getGroup())) {
                group.setText(capitalize(metadata.getGroup()));
                showGroup();
            }
            if (isNotEmpty(metadata.getRating())) {
                rating.setText(metadata.getRating());
                showRating();
            }
            if (isNotEmpty(metadata.getPlace())) {
                place.setText("#" + metadata.getPlace());
                showPlace();
            }
            if (metadata.getImages().size() == 1) {
                try {
                    ReturningTask<Void> task2 = () -> {
                        TargetAndPath name = metadata.getImages().iterator().next();
                        fadeUpImage(new Image(CachedImageService.getInstance().getImage(name)));
                        return null;
                    };
                    ExecutorUtil.executeAsyncWithRetry(task2);
                } catch (Exception e) {
                    imageView.setImage(metaDataSercice.getNoPreview());
                }
            } else if (metadata.getImages().size() > 1) {
                loopImages(metadata.getImages());
            } else {
                fadeUpImage(metaDataSercice.getNoPreview());
            }
        });
        return null;
    };
    ExecutorUtil.executeAsyncWithRetry(task);
    this.searchedItem = searchedItem;
    name.setCellValueFactory(new PropertyValueFactory<ContentEntry, String>("name"));
    EventHandler<MouseEvent> mouseEventHandle = (MouseEvent event) -> {
        handleMouseClicked(event);
    };
    table.addEventHandler(MouseEvent.MOUSE_PRESSED, mouseEventHandle);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    contentEntry.getContentEntry().sort((i1, i2) -> i1.getName().toLowerCase().compareTo(i2.getName().toLowerCase()));
    data.addAll(contentEntry.getContentEntry());
    table.setItems(data);
    getStage().setOnCloseRequest(event -> {
        closeImageLoop();
    });
    table.setOnKeyTyped(event -> {
        if (event.getCharacter().charAt(0) == Support.ENTER_KEY) {
            openFile(false);
        }
    });
    Executors.newSingleThreadExecutor().execute(() -> {
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
        }
        Platform.runLater(() -> {
            GuiUtils.selectFirstInList(table);
        });
    });
}
Also used : TargetAndPath(se.light.assembly64.model.TargetAndPath) MouseEvent(javafx.scene.input.MouseEvent) ReturningTask(se.light.assembly64.model.ReturningTask) Image(javafx.scene.image.Image) MetadataService(se.light.assembly64.fx.mdresolve.MetadataService) ContentEntry(se.light.assembly64.model.ContentEntry)

Example 2 with ViceService

use of se.light.assembly64.service.ViceService 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 Image (javafx.scene.image.Image)1 MouseEvent (javafx.scene.input.MouseEvent)1 Text (javafx.scene.text.Text)1 CbmFile (se.light.assembly64.d64.CbmFile)1 MetadataService (se.light.assembly64.fx.mdresolve.MetadataService)1 ContentEntry (se.light.assembly64.model.ContentEntry)1 ReturningTask (se.light.assembly64.model.ReturningTask)1 TargetAndPath (se.light.assembly64.model.TargetAndPath)1