eirikbakke commented on code in PR #9303:
URL: https://github.com/apache/netbeans/pull/9303#discussion_r3016111103


##########
platform/core.startup/src/org/netbeans/core/startup/Splash.java:
##########
@@ -265,17 +284,91 @@ public void flushCaches(DataOutputStream os) throws 
IOException {
     @Override
     public void cacheReady() {
     }
+    
+    private static void onEDT(Runnable edtAction) {
+        if (SwingUtilities.isEventDispatchThread()) {
+            edtAction.run();
+        } else {
+            SwingUtilities.invokeLater(edtAction);
+        }
+    }
+
+    private static class Progress {
+
+        private volatile int progress = 0;
+        private volatile int maxSteps = 0;
+        private volatile int barStart = 0;
+        private volatile int barLength = 0;
+        private volatile String text;
+
+        private void incrementProgress(SplashPainter painter, int steps) {
+            if (steps <= 0) {
+                return;
+            }
+            progress += steps;
+            if (progress > maxSteps) {
+                progress = maxSteps;
+            } else if (maxSteps > 0 && painter != null) {
+                int bl = painter.bar.width * progress / maxSteps - barStart;
+                if (bl > 1 || barStart % 2 == 0) {
+                    barLength = bl;
+                    onEDT(() -> {
+                        /* Don't try to be smart about which section of the 
bar to repaint.
+                        There can be tricky rounding issues on HiDPI screens 
with non-integral
+                        scaling factors (e.g. 150%). */
+                        painter.repaint(painter.bar);
+                    });
+                }
+            }
+        }
+
+        /**
+         * Adds space for given number of steps.
+         * It also alters progress to preserve ratio between completed and 
total
+         * number of steps.
+         */
+        private void incrementMaxSteps(int steps) {
+            if (steps == 0) {
+                return;
+            }
+            if (maxSteps == 0) {
+                int prog = progress / steps;
+                maxSteps = steps;
+                progress = prog;
+            } else {
+                int max = maxSteps + steps;
+                int prog = progress * max / maxSteps;
+                maxSteps = max;
+                progress = prog;
+            }
+            // do repaint on next increment
+        }
+
+        /**
+         * Defines the single line of text this component will display.
+         */
+        private void setText(SplashPainter painter, String text) {
+            if (text != null && text.equals(this.text)) {
+                return;
+            }
+            this.text = text;
+            if (painter == null) {
+                return;
+            }
+            onEDT(() -> {
+                painter.setText(this.text);

Review Comment:
   The existing logic here is really messy, with the text stored in both 
Progress and in SplashPainter, and updated from both. But probably best to 
leave it as it is. It's at least more thread-safe now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to