Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate dependency on Swing and call to invokeLater #345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ synchronized static void register(Listener onChange) {
}
}

synchronized static void notifyUpdates(Handle h, int type) {
private synchronized static void notifyUpdates(Handle h, Type type) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how bout ?

private synchronized static void notifyUpdates(Handle h, BiConsumer<Listener, Handle> c) {
    for (Listener onChange : listeners) {
         c.accept(onChange, h);
     }
}

and then call it like

    @Override
    public void close() {
        notifyUpdates(this, 2);
        notifyUpdates(this, Listener::finished);
    }

for (Listener onChange : listeners) {
switch (type) {
case 1: onChange.started(h); break;
case 2: onChange.progress(h); break;
case STARTED: onChange.started(h); break;
case PROGRESS: onChange.progress(h); break;
default: onChange.finished(h);
}
}
}

private enum Type {
STARTED, PROGRESS, FINISHED;
}

static interface Listener {
void started(Handle h);
void progress(Handle h);
Expand All @@ -75,7 +79,7 @@ static final class Handle implements AutoCloseable {

private Handle(Progress type) {
this.type = type;
notifyUpdates(this, 1);
notifyUpdates(this, Type.STARTED);
}

void progress(long value, long endValue) {
Expand All @@ -91,14 +95,14 @@ void progress(long counter, long startOffset, long value, long endOffset) {

@Override
public void close() {
notifyUpdates(this, 2);
notifyUpdates(this, Type.FINISHED);
}

private void doProgress(long value, long startOffset, long endOffset) {
this.value = value;
this.endOffset = endOffset;
this.startOffset = startOffset;
notifyUpdates(this, 1);
notifyUpdates(this, Type.PROGRESS);
}

long getValue() {
Expand Down