mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
less PotemkinProgress overhead in checkCanceled (IDEA-170011)
do nothing if the progress isn't shown yet call SunToolkit.flushPendingEvents less frequently
This commit is contained in:
+20
-10
@@ -67,8 +67,11 @@ public class PotemkinProgress extends ProgressWindow {
|
||||
|
||||
public void interact() {
|
||||
if (ApplicationManager.getApplication().isDispatchThread()) {
|
||||
dispatchAwtEventsWithoutModelAccess(0);
|
||||
updateUI();
|
||||
long now = System.currentTimeMillis();
|
||||
if (shouldDispatchAwtEvents(now)) {
|
||||
dispatchAwtEventsWithoutModelAccess(0);
|
||||
}
|
||||
updateUI(now);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +90,14 @@ public class PotemkinProgress extends ProgressWindow {
|
||||
}
|
||||
}
|
||||
|
||||
private long myLastShouldDispatchCheck = 0;
|
||||
private boolean shouldDispatchAwtEvents(long now) {
|
||||
if (now == myLastShouldDispatchCheck) return false;
|
||||
|
||||
myLastShouldDispatchCheck = now;
|
||||
return getDialog().getPanel().isShowing();
|
||||
}
|
||||
|
||||
private void dispatchInputEvent(InputEvent e) {
|
||||
if (isCancellationEvent(e)) {
|
||||
cancel();
|
||||
@@ -104,20 +115,20 @@ public class PotemkinProgress extends ProgressWindow {
|
||||
return dialogWindow instanceof JDialog && SwingUtilities.isDescendingFrom(source, dialogWindow);
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
private void updateUI(long now) {
|
||||
JRootPane rootPane = getDialog().getPanel().getRootPane();
|
||||
if (rootPane == null) {
|
||||
rootPane = considerShowingDialog();
|
||||
rootPane = considerShowingDialog(now);
|
||||
}
|
||||
|
||||
if (rootPane != null && timeToPaint()) {
|
||||
if (rootPane != null && timeToPaint(now)) {
|
||||
paintProgress();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JRootPane considerShowingDialog() {
|
||||
if (System.currentTimeMillis() - myLastUiUpdate > DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS) {
|
||||
private JRootPane considerShowingDialog(long now) {
|
||||
if (now - myLastUiUpdate > DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS) {
|
||||
getDialog().myRepaintRunnable.run();
|
||||
showDialog();
|
||||
return getDialog().getPanel().getRootPane();
|
||||
@@ -125,8 +136,7 @@ public class PotemkinProgress extends ProgressWindow {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean timeToPaint() {
|
||||
long now = System.currentTimeMillis();
|
||||
private boolean timeToPaint(long now) {
|
||||
if (now - myLastUiUpdate <= ProgressDialog.UPDATE_INTERVAL) {
|
||||
return false;
|
||||
}
|
||||
@@ -172,7 +182,7 @@ public class PotemkinProgress extends ProgressWindow {
|
||||
|
||||
while (isRunning()) {
|
||||
dispatchAwtEventsWithoutModelAccess(10);
|
||||
updateUI();
|
||||
updateUI(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
||||
Reference in New Issue
Block a user