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

Replace EventDispatcher with Guava's EventBus #3741

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
85 changes: 0 additions & 85 deletions src/main/java/net/rptools/lib/EventDispatcher.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.rptools.maptool.client.ui.zone.FogUtil;
import net.rptools.maptool.client.ui.zone.ZoneRenderer;
import net.rptools.maptool.client.ui.zone.ZoneRendererFactory;
import net.rptools.maptool.events.MapToolEventBus;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.model.Asset;
import net.rptools.maptool.model.AssetManager;
Expand Down Expand Up @@ -59,6 +60,7 @@
import net.rptools.maptool.model.library.addon.AddOnLibraryImporter;
import net.rptools.maptool.model.library.addon.TransferableAddOnLibrary;
import net.rptools.maptool.model.player.Player;
import net.rptools.maptool.model.zones.ZoneAdded;
import net.rptools.maptool.server.Mapper;
import net.rptools.maptool.server.ServerMessageHandler;
import net.rptools.maptool.server.ServerPolicy;
Expand Down Expand Up @@ -729,8 +731,7 @@ private void handle(PutZoneMsg msg) {
if (MapTool.getFrame().getCurrentZoneRenderer() == null && zone.isVisible()) {
MapTool.getFrame().setCurrentZoneRenderer(renderer);
}
MapTool.getEventDispatcher()
.fireEvent(MapTool.ZoneEvent.Added, MapTool.getCampaign(), null, zone);
new MapToolEventBus().getMainEventBus().post(new ZoneAdded(zone));
});
}

Expand Down
31 changes: 4 additions & 27 deletions src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import javax.swing.plaf.FontUIResource;
import net.rptools.lib.BackupManager;
import net.rptools.lib.DebugStream;
import net.rptools.lib.EventDispatcher;
import net.rptools.lib.FileUtil;
import net.rptools.lib.TaskBarFlasher;
import net.rptools.lib.image.ThumbnailManager;
Expand All @@ -73,6 +72,7 @@
import net.rptools.maptool.client.ui.zone.PlayerView;
import net.rptools.maptool.client.ui.zone.ZoneRenderer;
import net.rptools.maptool.client.ui.zone.ZoneRendererFactory;
import net.rptools.maptool.events.MapToolEventBus;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.model.AssetManager;
import net.rptools.maptool.model.Campaign;
Expand All @@ -88,6 +88,7 @@
import net.rptools.maptool.model.player.PlayerDatabase;
import net.rptools.maptool.model.player.PlayerDatabaseFactory;
import net.rptools.maptool.model.player.Players;
import net.rptools.maptool.model.zones.ZoneAdded;
import net.rptools.maptool.protocol.syrinscape.SyrinscapeURLStreamHandler;
import net.rptools.maptool.server.MapToolServer;
import net.rptools.maptool.server.ServerCommand;
Expand Down Expand Up @@ -131,17 +132,6 @@ public class MapTool {

private static String clientId = AppUtil.readClientId();

public enum ZoneEvent {
Added,
Removed,
Activated,
Deactivated
}

public enum PreferencesEvent {
Changed
}

// Jamz: This sets the thumbnail size that is cached for imageThumbs
// Set it to 500 (from 100) for now to support larger asset window previews
// TODO: Add preferences option as well as add auto-purge after x days preferences
Expand Down Expand Up @@ -174,7 +164,6 @@ public enum PreferencesEvent {
private static ServiceAnnouncer announcer;
private static AutoSaveManager autoSaveManager;
private static TaskBarFlasher taskbarFlasher;
private static EventDispatcher eventDispatcher;
private static MapToolLineParser parser = new MapToolLineParser();
private static String lastWhisperer;

Expand Down Expand Up @@ -589,15 +578,6 @@ public static AutoSaveManager getAutoSaveManager() {
return autoSaveManager;
}

public static EventDispatcher getEventDispatcher() {
return eventDispatcher;
}

private static void registerEvents() {
getEventDispatcher().registerEvents(ZoneEvent.values());
getEventDispatcher().registerEvents(PreferencesEvent.values());
}

/**
* This was added to make it easier to set a breakpoint and locate when the frame was initialized.
*
Expand Down Expand Up @@ -660,9 +640,6 @@ private static void initialize() {
// We'll manage our own images
ImageIO.setUseCache(false);

eventDispatcher = new EventDispatcher();
registerEvents();

try {
SoundManager.configure(SOUND_PROPERTIES);
SoundManager.registerSoundEvent(
Expand Down Expand Up @@ -982,7 +959,7 @@ public static void setCampaign(Campaign campaign, GUID defaultRendererId) {
&& (getPlayer().isGM() || zone.isVisible())) {
currRenderer = renderer;
}
eventDispatcher.fireEvent(ZoneEvent.Added, campaign, null, zone);
new MapToolEventBus().getMainEventBus().post(new ZoneAdded(zone));
}
clientFrame.setCurrentZoneRenderer(currRenderer);
clientFrame.getInitiativePanel().setOwnerPermissions(campaign.isInitiativeOwnerPermissions());
Expand Down Expand Up @@ -1159,7 +1136,7 @@ public static void addZone(Zone zone, boolean changeZone) {
}
getCampaign().putZone(zone);
serverCommand().putZone(zone);
eventDispatcher.fireEvent(ZoneEvent.Added, getCampaign(), null, zone);
new MapToolEventBus().getMainEventBus().post(new ZoneAdded(zone));

// Show the new zone
if (changeZone) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.lib;
package net.rptools.maptool.client.events;

public interface AppEventListener {

public void handleAppEvent(AppEvent event);
}
public record PreferencesChanged() {}
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,8 @@
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.lib;
package net.rptools.maptool.client.events;

public class AppEvent {
import net.rptools.maptool.model.Zone;

private Enum<?> id;
private Object source;
private Object oldValue;
private Object newValue;

public AppEvent(Enum<?> id, Object source, Object oldValue, Object newValue) {
this.id = id;
this.source = source;
this.oldValue = oldValue;
this.newValue = newValue;
}

public Enum<?> getId() {
return id;
}

public Object getSource() {
return source;
}

public Object getOldValue() {
return oldValue;
}

public Object getNewValue() {
return newValue;
}
}
public record ZoneActivated(Zone zone) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.maptool.client.events;

import net.rptools.maptool.model.Zone;

public record ZoneDeactivated(Zone zone) {}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.client.tool.drawing;

import com.google.common.eventbus.Subscribe;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
Expand All @@ -25,23 +26,22 @@
import java.util.Map;
import java.util.Set;
import javax.swing.*;
import net.rptools.lib.AppEvent;
import net.rptools.lib.AppEventListener;
import net.rptools.lib.image.ImageUtil;
import net.rptools.maptool.client.*;
import net.rptools.maptool.client.events.ZoneActivated;
import net.rptools.maptool.client.tool.DefaultTool;
import net.rptools.maptool.client.tool.LayerSelectionDialog;
import net.rptools.maptool.client.ui.drawpanel.DrawPanelPopupMenu;
import net.rptools.maptool.client.ui.zone.ZoneOverlay;
import net.rptools.maptool.client.ui.zone.ZoneRenderer;
import net.rptools.maptool.events.MapToolEventBus;
import net.rptools.maptool.model.GUID;
import net.rptools.maptool.model.Zone.Layer;
import net.rptools.maptool.model.ZonePoint;
import net.rptools.maptool.model.drawing.DrawnElement;

/** Tool for deleting drawings. */
public class DeleteDrawingTool extends DefaultTool
implements ZoneOverlay, MouseListener, AppEventListener {
public class DeleteDrawingTool extends DefaultTool implements ZoneOverlay, MouseListener {

@Serial private static final long serialVersionUID = -8846217296437736953L;

Expand All @@ -59,7 +59,7 @@ public class DeleteDrawingTool extends DefaultTool
public DeleteDrawingTool() {
try {
setIcon(new ImageIcon(ImageUtil.getImage("net/rptools/maptool/client/image/delete.png")));
MapTool.getEventDispatcher().addListener(this, MapTool.ZoneEvent.Activated);
new MapToolEventBus().getMainEventBus().register(this);
} catch (IOException ioe) {
ioe.printStackTrace();
}
Expand Down Expand Up @@ -148,10 +148,8 @@ private void drawBox(Graphics2D g, DrawnElement element) {
AppStyle.selectedBorder.paintAround(g, x, y, w, h);
}

@Override
public void handleAppEvent(AppEvent event) {
if (event.getId() != MapTool.ZoneEvent.Activated) return;

@Subscribe
void onZoneActivated(ZoneActivated event) {
selectedDrawings.clear();
}
}
Loading