Skip to content

Commit

Permalink
Get rid of some dead code in NbClipboard.
Browse files Browse the repository at this point in the history
The fields lastWindowActivated, lastWindowDeactivated, and lastWindowDeactivatedSource, and the related conditions were no longer in actual use; this can be seen by reading through the code.

It seems the condition that once used lastWindowActivated was at some point replaced by a call to Task.waitFinished. So there wasn't a mistake; just some unused code left around. See the relevant commit from 2012: eirikbakke/netbeans-releases@6de619c#diff-69d67e2e5b062ae995069c62294958e6e24a42c599cc6684c47f89b086c20278
  • Loading branch information
eirikbakke committed Aug 12, 2024
1 parent c0e3d71 commit fb59d75
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
17 changes: 3 additions & 14 deletions platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ public final class NbClipboard extends ExClipboard
private Lookup.Result<ExClipboard.Convertor> result;
final boolean slowSystemClipboard;
private Transferable last;
private long lastWindowActivated;
private long lastWindowDeactivated;
private Reference<Object> lastWindowDeactivatedSource = new WeakReference<>(null);
private volatile Task setContentsTask = Task.EMPTY;
private volatile Task getContentsTask = Task.EMPTY;
private boolean anyWindowIsActivated = true;
Expand Down Expand Up @@ -280,14 +277,12 @@ final void waitFinished () {
getContentsTask.waitFinished ();
}

final void activateWindowHack (boolean reschedule) {
/** Used by tests only. */
final void activateWindowHack () {
// if WINDOW_DEACTIVATED is followed immediatelly with
// WINDOW_ACTIVATED then it is JDK bug described in
// issue 41098.
lastWindowActivated = System.currentTimeMillis();
if (reschedule) {
scheduleGetFromSystemClipboard(true);
}
scheduleGetFromSystemClipboard(true);
}

private void logFlavors (Transferable trans, Level level, boolean content) {
Expand Down Expand Up @@ -341,8 +336,6 @@ public void eventDispatched(AWTEvent ev) {
return;

if (ev.getID() == WindowEvent.WINDOW_DEACTIVATED) {
lastWindowDeactivated = System.currentTimeMillis();
lastWindowDeactivatedSource = new WeakReference<>(ev.getSource());
anyWindowIsActivated = false;
if( Utilities.isWindows() ) {
/* Avoid calling add/removeFlavorListener from the Event Dispatch Thread, as these
Expand All @@ -368,10 +361,6 @@ public void eventDispatched(AWTEvent ev) {
});
}
anyWindowIsActivated = true;
if (System.currentTimeMillis() - lastWindowDeactivated < 100 &&
ev.getSource() == lastWindowDeactivatedSource.get()) {
activateWindowHack (false);
}
if (log.isLoggable (Level.FINE)) {
log.log (Level.FINE, "window activated scheduling update"); // NOI18N
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void testWhenCallingGetContentsItChecksSystemClipboardFirstTimeAfterActiv


// just simulate initial switch to NetBeans main window
ec.activateWindowHack (true);
ec.activateWindowHack ();
waitFinished (ec);

if (listenerCalls == 0) {
Expand Down Expand Up @@ -179,7 +179,7 @@ public void testWhenCallingGetContentsItChecksSystemClipboardFirstTimeAfterActiv
if (slowClipboardHack ()) {
assertEquals ("The getContents rechecked the clipboard just for the first time, not now, so the content is the same", "data2", s);

ec.activateWindowHack (true);
ec.activateWindowHack ();
Thread.sleep (200);

t = this.ec.getContents(this);
Expand Down

0 comments on commit fb59d75

Please sign in to comment.