Skip to content

Commit

Permalink
Allow things to stop events displaying.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Jan 16, 2015
1 parent f9bd291 commit cb33e97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/com/dmdirc/events/DisplayProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ public final class DisplayProperty<T> {
public static final DisplayProperty<Colour> FOREGROUND_COLOUR = new DisplayProperty<>();
/** The background colour of text relating to the event. */
public static final DisplayProperty<Colour> BACKGROUND_COLOUR = new DisplayProperty<>();
/** Whether to suppress display of the event. */
public static final DisplayProperty<Void> DO_NOT_DISPLAY = new DisplayProperty<>();

}
21 changes: 17 additions & 4 deletions src/com/dmdirc/ui/messages/BackBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

import com.dmdirc.DMDircMBassador;
import com.dmdirc.FrameContainer;
import com.dmdirc.events.DisplayProperty;
import com.dmdirc.events.DisplayableEvent;
import com.dmdirc.util.EventUtils;

import net.engio.mbassy.listener.Handler;

Expand Down Expand Up @@ -72,19 +74,30 @@ public void stopAddingEvents() {
*
* @param event The event to be displayed.
*/
@Handler
public void handleDisplayableEvent(final DisplayableEvent event) {
if (event.getSource().equals(owner)) {
@Handler(priority = EventUtils.PRIORITY_DISPLAYABLE_EVENT_HANDLER)
private void handleDisplayableEvent(final DisplayableEvent event) {
if (shouldDisplay(event)) {
formatter.format(event).map(s -> s.split("\n")).ifPresent(
t -> {
for (String line : t) {
document.addText(event.getTimestamp(), event
.getDisplayProperties(), line);
.getDisplayProperties(), line);
}
});
}
}

/**
* Determines if the specified event should be displayed in this backbuffer.
*
* @param event The event to check
* @return True if the event should be displayed, false otherwise.
*/
private boolean shouldDisplay(final DisplayableEvent event) {
return event.getSource().equals(owner)
&& !event.getDisplayProperty(DisplayProperty.DO_NOT_DISPLAY).isPresent();
}

public IRCDocument getDocument() {
return document;
}
Expand Down

0 comments on commit cb33e97

Please sign in to comment.