user25106225
user25106225

Reputation: 1

How do I integrate StorageService for a Java program using GluonHQ maps repository?

So, I have implemented GluonHQ maps into my project and I want to also implement the StorageService to load those maps offline, anyway I can't do that since I need some sort of ServiceFactory for the implementation which Java22 does not have anymore, this is my current code.

import com.gluonhq.attach.storage.StorageService;
 @Override
    public void start(Stage stage) throws Exception {
        String osName = System.getProperty("os.name").toLowerCase();
        if (osName.contains("win") || osName.contains("mac") || osName.contains("nix") || osName.contains("nux") || osName.contains("aix")) {
            System.setProperty("javafx.platform", "Desktop");
        }

        // Create a StorageService instance
        StorageService storageService = new StorageService() {
            @Override
            public Optional<File> getPrivateStorage() {
                return Optional.of(new File(System.getProperty("user.home")));
            }

            @Override
            public Optional<File> getPublicStorage(String subdirectory) {
                return getPrivateStorage();
            }

            @Override
            public boolean isExternalStorageWritable() {
                return getPrivateStorage().get().canWrite();
            }

            @Override
            public boolean isExternalStorageReadable() {
                return getPrivateStorage().get().canRead();
            }
        };

        // Register the StorageService directly using Services utility

        final String uiFXMLPath = "uiPh1.fxml";
        Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource(uiFXMLPath)));
        stage.setScene(new Scene(root));
        stage.show();
        root.requestFocus();
    }

I tried several libraries that have the Service Factory implemented but none work, can you help me?

Upvotes: 0

Views: 41

Answers (0)

Related Questions