All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pepsoft.util.ProgressHelperJava9 Maven / Gradle / Ivy

There is a newer version: 2.23.2
Show newest version
package org.pepsoft.util;

import java.awt.*;
import java.util.Map;
import java.util.WeakHashMap;

import static java.awt.Taskbar.Feature.PROGRESS_STATE_WINDOW;
import static java.awt.Taskbar.Feature.PROGRESS_VALUE_WINDOW;

class ProgressHelperJava9 extends ProgressHelper {
    ProgressHelperJava9() {
        enabled = Taskbar.isTaskbarSupported()
                && Taskbar.getTaskbar().isSupported(PROGRESS_VALUE_WINDOW)
                && Taskbar.getTaskbar().isSupported(PROGRESS_STATE_WINDOW);
    }

    @Override
    void setProgress(Window window, int percentage) {
        if (! enabled) {
            return;
        }
        if (errorStates.getOrDefault(window, false)) {
            return;
        }
        Taskbar.getTaskbar().setWindowProgressValue(window, percentage);
    }

    @Override
    void setProgressDone(Window window) {
        if (! enabled) {
            return;
        }
        Taskbar.getTaskbar().setWindowProgressState(window, Taskbar.State.OFF);
        errorStates.remove(window);
    }

    @Override
    void setProgressError(Window window) {
        if (! enabled) {
            return;
        }
        if (errorStates.getOrDefault(window, false)) {
            return;
        } else {
            errorStates.put(window, true);
        }
        Taskbar.getTaskbar().setWindowProgressState(window, Taskbar.State.ERROR);
    }

    private final boolean enabled;
    private final Map errorStates = new WeakHashMap<>();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy