|
| 1 | +package org.redlance.platformtools; |
| 2 | + |
| 3 | +import org.redlance.platformtools.impl.PlatformProgressBarImpl; |
| 4 | + |
| 5 | +import java.io.Closeable; |
| 6 | + |
| 7 | +/** |
| 8 | + * Factory interface for creating platform-specific progress bar indicators. |
| 9 | + * <p> |
| 10 | + * This interface provides a platform-agnostic way to display progress bars |
| 11 | + * in native UI elements (such as the macOS dock icon). |
| 12 | + * <p> |
| 13 | + * Usage example: |
| 14 | + * <pre>{@code |
| 15 | + * PlatformProgressBars.PlatformProgressBar progressBar = PlatformProgressBars.INSTANCE.create(); |
| 16 | + * progressBar.setMaxValue(100); |
| 17 | + * progressBar.display(); |
| 18 | + * progressBar.setValue(50); |
| 19 | + * // ... when done |
| 20 | + * progressBar.close(); |
| 21 | + * }</pre> |
| 22 | + * |
| 23 | + * @see PlatformProgressBar |
| 24 | + * @see BasePlatformFeature#isAvailable() |
| 25 | + */ |
| 26 | +@SuppressWarnings("unused") // API |
| 27 | +public interface PlatformProgressBars extends BasePlatformFeature { |
| 28 | + /** |
| 29 | + * Singleton instance of the platform-specific progress bar factory. |
| 30 | + */ |
| 31 | + PlatformProgressBars INSTANCE = new PlatformProgressBarImpl(); |
| 32 | + |
| 33 | + /** |
| 34 | + * Creates a new platform-specific progress bar instance. |
| 35 | + * <p> |
| 36 | + * The returned progress bar is not visible until {@link PlatformProgressBar#display()} is called. |
| 37 | + * |
| 38 | + * @return a new {@link PlatformProgressBar} instance |
| 39 | + * @throws TooManyProgressBarsException if the maximum number of progress bars has been reached |
| 40 | + */ |
| 41 | + PlatformProgressBar create() throws TooManyProgressBarsException; |
| 42 | + |
| 43 | + /** |
| 44 | + * Represents a platform-specific progress bar that can be displayed |
| 45 | + * in native UI elements. |
| 46 | + */ |
| 47 | + interface PlatformProgressBar extends Closeable { |
| 48 | + /** |
| 49 | + * Displays the progress bar in the native UI element. |
| 50 | + * <p> |
| 51 | + * This method should be called after configuring the progress bar |
| 52 | + * with {@link #setMaxValue(double)} and optionally {@link #setValue(double)}. |
| 53 | + */ |
| 54 | + void display(); |
| 55 | + |
| 56 | + /** |
| 57 | + * Removes the progress bar from the native UI element. |
| 58 | + * <p> |
| 59 | + * After calling this method, the progress bar will no longer be visible. |
| 60 | + */ |
| 61 | + @Override |
| 62 | + void close(); |
| 63 | + |
| 64 | + /** |
| 65 | + * Increments the current progress value by the specified amount. |
| 66 | + * |
| 67 | + * @param progress the amount to add to the current value |
| 68 | + */ |
| 69 | + void incrementBy(double progress); |
| 70 | + |
| 71 | + /** |
| 72 | + * Sets the maximum value of the progress bar. |
| 73 | + * |
| 74 | + * @param maxValue the maximum progress value |
| 75 | + */ |
| 76 | + void setMaxValue(double maxValue); |
| 77 | + |
| 78 | + /** |
| 79 | + * Sets the current progress value. |
| 80 | + * |
| 81 | + * @param value the current progress value (should be between 0 and maxValue) |
| 82 | + */ |
| 83 | + void setValue(double value); |
| 84 | + |
| 85 | + /** |
| 86 | + * Sets whether the progress bar is in indeterminate mode. |
| 87 | + * <p> |
| 88 | + * In indeterminate mode, the progress bar shows an animated state |
| 89 | + * indicating that work is in progress but the amount is unknown. |
| 90 | + * |
| 91 | + * @param indeterminate true for indeterminate mode, false for determinate |
| 92 | + */ |
| 93 | + void setIndeterminate(boolean indeterminate); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Thrown when attempting to create more progress bars than the platform supports. |
| 98 | + */ |
| 99 | + class TooManyProgressBarsException extends RuntimeException { |
| 100 | + private final int maxAllowed; |
| 101 | + |
| 102 | + public TooManyProgressBarsException(int maxAllowed) { |
| 103 | + super("Too many progress bars. Maximum allowed: " + maxAllowed); |
| 104 | + this.maxAllowed = maxAllowed; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Returns the maximum number of progress bars allowed on this platform. |
| 109 | + * |
| 110 | + * @return maximum allowed progress bars |
| 111 | + */ |
| 112 | + public int getMaxAllowed() { |
| 113 | + return this.maxAllowed; |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments