From 8a71eab41a79d4604f09df4f2cf0f127c92618c0 Mon Sep 17 00:00:00 2001 From: Louis Bergelson Date: Thu, 19 Oct 2023 15:32:10 -0400 Subject: [PATCH] Make IGV events all implement sealed interface IGVEvent This isn't really a functional change but makes it a bit easier to find/understand what event types are available. --- src/main/java/module-info.java | 1 + .../broad/igv/event/AlignmentTrackEvent.java | 2 +- .../org/broad/igv/event/DataLoadedEvent.java | 2 +- .../broad/igv/event/GenomeChangeEvent.java | 2 +- .../org/broad/igv/event/GenomeResetEvent.java | 2 +- .../java/org/broad/igv/event/IGVEvent.java | 23 +++++++++++++++++++ .../java/org/broad/igv/event/IGVEventBus.java | 2 +- .../org/broad/igv/event/IGVEventObserver.java | 2 +- .../org/broad/igv/event/RefreshEvent.java | 2 +- .../java/org/broad/igv/event/StopEvent.java | 2 +- .../org/broad/igv/event/TrackGroupEvent.java | 2 +- .../java/org/broad/igv/event/ViewChange.java | 2 +- .../org/broad/igv/oauth/OAuthProvider.java | 3 ++- .../igv/prefs/PreferencesChangeEvent.java | 4 +++- .../broad/igv/prefs/PreferencesManager.java | 3 ++- .../broad/igv/sam/AlignmentDataManager.java | 3 ++- .../broad/igv/sam/AlignmentTileLoader.java | 3 ++- .../org/broad/igv/sam/AlignmentTrack.java | 3 ++- .../igv/sam/InsertionSelectionEvent.java | 4 +++- .../org/broad/igv/sashimi/SashimiPlot.java | 3 ++- .../java/org/broad/igv/session/Session.java | 3 ++- .../java/org/broad/igv/track/DataTrack.java | 3 ++- .../org/broad/igv/track/FeatureTrack.java | 3 ++- .../org/broad/igv/track/SequenceTrack.java | 3 ++- src/main/java/org/broad/igv/ui/IGV.java | 4 ++-- .../java/org/broad/igv/ui/IGVMenuBar.java | 6 ++--- .../igv/ui/commandbar/IGVCommandBar.java | 12 ++++------ .../org/broad/igv/ui/panel/CytobandPanel.java | 6 ++--- .../org/broad/igv/ui/panel/DataPanel.java | 11 ++++----- .../org/broad/igv/ui/panel/FrameManager.java | 5 ++-- .../org/broad/igv/ui/panel/HeaderPanel.java | 4 ++-- .../broad/igv/ui/panel/ReferenceFrame.java | 14 +++++------ .../igv/ui/panel/RegionNavigatorDialog.java | 3 ++- .../igv/ui/util/ApplicationStatusBar.java | 6 ++--- .../org/broad/igv/variant/VariantTrack.java | 3 ++- 35 files changed, 93 insertions(+), 63 deletions(-) create mode 100644 src/main/java/org/broad/igv/event/IGVEvent.java diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 15bb2a73f2..a90a088280 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -2,6 +2,7 @@ exports org.broad.igv; exports org.broad.igv.tools; exports org.broad.igv.ui; + exports org.broad.igv.event; exports org.broad.igv.jbrowse; exports org.broad.igv.logging; exports org.broad.igv.util.liftover; diff --git a/src/main/java/org/broad/igv/event/AlignmentTrackEvent.java b/src/main/java/org/broad/igv/event/AlignmentTrackEvent.java index e78055b20c..c1b4091051 100644 --- a/src/main/java/org/broad/igv/event/AlignmentTrackEvent.java +++ b/src/main/java/org/broad/igv/event/AlignmentTrackEvent.java @@ -29,6 +29,6 @@ * @author Jim Robinson * @date 12/2/11 */ -public record AlignmentTrackEvent(Type type) { +public record AlignmentTrackEvent(Type type) implements IGVEvent{ public enum Type {ALLELE_THRESHOLD, RELOAD, REFRESH} } \ No newline at end of file diff --git a/src/main/java/org/broad/igv/event/DataLoadedEvent.java b/src/main/java/org/broad/igv/event/DataLoadedEvent.java index cd04e37cc7..5d946a03db 100644 --- a/src/main/java/org/broad/igv/event/DataLoadedEvent.java +++ b/src/main/java/org/broad/igv/event/DataLoadedEvent.java @@ -31,4 +31,4 @@ * User: jacob * Date: 2013-Feb-06 */ -public record DataLoadedEvent(ReferenceFrame referenceFrame) {} +public record DataLoadedEvent(ReferenceFrame referenceFrame) implements IGVEvent {} diff --git a/src/main/java/org/broad/igv/event/GenomeChangeEvent.java b/src/main/java/org/broad/igv/event/GenomeChangeEvent.java index 9722ec597f..5213a9128a 100644 --- a/src/main/java/org/broad/igv/event/GenomeChangeEvent.java +++ b/src/main/java/org/broad/igv/event/GenomeChangeEvent.java @@ -31,4 +31,4 @@ /** * Created by jrobinso on 1/7/17. */ -public record GenomeChangeEvent(Genome genome) {} +public record GenomeChangeEvent(Genome genome) implements IGVEvent {} diff --git a/src/main/java/org/broad/igv/event/GenomeResetEvent.java b/src/main/java/org/broad/igv/event/GenomeResetEvent.java index b9289e97bf..57cc637379 100644 --- a/src/main/java/org/broad/igv/event/GenomeResetEvent.java +++ b/src/main/java/org/broad/igv/event/GenomeResetEvent.java @@ -3,5 +3,5 @@ /** * Created by jrobinso on 2/7/17. */ -public class GenomeResetEvent { +public final class GenomeResetEvent implements IGVEvent { } diff --git a/src/main/java/org/broad/igv/event/IGVEvent.java b/src/main/java/org/broad/igv/event/IGVEvent.java new file mode 100644 index 0000000000..d77051b4a8 --- /dev/null +++ b/src/main/java/org/broad/igv/event/IGVEvent.java @@ -0,0 +1,23 @@ +package org.broad.igv.event; + +import org.broad.igv.oauth.OAuthProvider; +import org.broad.igv.prefs.PreferencesChangeEvent; +import org.broad.igv.sam.InsertionSelectionEvent; +import org.broad.igv.ui.panel.FrameManager; + +public sealed interface IGVEvent + permits + AlignmentTrackEvent, + DataLoadedEvent, + GenomeChangeEvent, + GenomeResetEvent, + RefreshEvent, + StopEvent, + TrackGroupEvent, + ViewChange, + OAuthProvider.AuthStateEvent, + PreferencesChangeEvent, + InsertionSelectionEvent, + FrameManager.ChangeEvent { + +} diff --git a/src/main/java/org/broad/igv/event/IGVEventBus.java b/src/main/java/org/broad/igv/event/IGVEventBus.java index 83101fb476..d91907823a 100644 --- a/src/main/java/org/broad/igv/event/IGVEventBus.java +++ b/src/main/java/org/broad/igv/event/IGVEventBus.java @@ -67,7 +67,7 @@ public synchronized void unsubscribe(IGVEventObserver observer) { } } - public void post(Object event) { + public void post(IGVEvent event) { Set observerSet = observerMap.get(event.getClass()); if (observerSet != null) { // Make a copy in case original is modified during loop diff --git a/src/main/java/org/broad/igv/event/IGVEventObserver.java b/src/main/java/org/broad/igv/event/IGVEventObserver.java index 954c6689f3..43e35b2b6a 100644 --- a/src/main/java/org/broad/igv/event/IGVEventObserver.java +++ b/src/main/java/org/broad/igv/event/IGVEventObserver.java @@ -31,6 +31,6 @@ */ public interface IGVEventObserver { - void receiveEvent(Object event); + void receiveEvent(IGVEvent event); } diff --git a/src/main/java/org/broad/igv/event/RefreshEvent.java b/src/main/java/org/broad/igv/event/RefreshEvent.java index fea6cb3f30..71ecf24eca 100644 --- a/src/main/java/org/broad/igv/event/RefreshEvent.java +++ b/src/main/java/org/broad/igv/event/RefreshEvent.java @@ -3,5 +3,5 @@ /** * Created by jrobinso on 6/24/17. */ -public class RefreshEvent { +public final class RefreshEvent implements IGVEvent { } diff --git a/src/main/java/org/broad/igv/event/StopEvent.java b/src/main/java/org/broad/igv/event/StopEvent.java index eacd355084..7173041a91 100644 --- a/src/main/java/org/broad/igv/event/StopEvent.java +++ b/src/main/java/org/broad/igv/event/StopEvent.java @@ -3,5 +3,5 @@ /** * Created by jrobinso on 6/24/17. */ -public class StopEvent { +public final class StopEvent implements IGVEvent{ } diff --git a/src/main/java/org/broad/igv/event/TrackGroupEvent.java b/src/main/java/org/broad/igv/event/TrackGroupEvent.java index 9df8e97319..71cef9e812 100644 --- a/src/main/java/org/broad/igv/event/TrackGroupEvent.java +++ b/src/main/java/org/broad/igv/event/TrackGroupEvent.java @@ -29,5 +29,5 @@ * @author Jim Robinson * @date 10/28/11 */ -public class TrackGroupEvent { +public final class TrackGroupEvent implements IGVEvent { } diff --git a/src/main/java/org/broad/igv/event/ViewChange.java b/src/main/java/org/broad/igv/event/ViewChange.java index 95b204673d..bd5d216e84 100644 --- a/src/main/java/org/broad/igv/event/ViewChange.java +++ b/src/main/java/org/broad/igv/event/ViewChange.java @@ -37,7 +37,7 @@ * User: jacob * Date: 2013-Jan-30 */ -public final class ViewChange { +public final class ViewChange implements IGVEvent{ public enum Type {ChromosomeChange, LocusChange} diff --git a/src/main/java/org/broad/igv/oauth/OAuthProvider.java b/src/main/java/org/broad/igv/oauth/OAuthProvider.java index f10158bf10..9e0734ee5a 100644 --- a/src/main/java/org/broad/igv/oauth/OAuthProvider.java +++ b/src/main/java/org/broad/igv/oauth/OAuthProvider.java @@ -5,6 +5,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; +import org.broad.igv.event.IGVEvent; import org.broad.igv.logging.*; import org.broad.igv.batch.CommandListener; import org.broad.igv.event.IGVEventBus; @@ -440,7 +441,7 @@ public String getAuthProvider() { } // Assuming that if this event is called, we are indeed autz/authn'd - public record AuthStateEvent(boolean authenticated, String authProvider, String userName) {} + public record AuthStateEvent(boolean authenticated, String authProvider, String userName) implements IGVEvent {} } diff --git a/src/main/java/org/broad/igv/prefs/PreferencesChangeEvent.java b/src/main/java/org/broad/igv/prefs/PreferencesChangeEvent.java index e2e5b95d75..8df8511011 100644 --- a/src/main/java/org/broad/igv/prefs/PreferencesChangeEvent.java +++ b/src/main/java/org/broad/igv/prefs/PreferencesChangeEvent.java @@ -1,7 +1,9 @@ package org.broad.igv.prefs; +import org.broad.igv.event.IGVEvent; + /** * Created by jrobinso on 1/22/17. */ -public class PreferencesChangeEvent { +public final class PreferencesChangeEvent implements IGVEvent { } diff --git a/src/main/java/org/broad/igv/prefs/PreferencesManager.java b/src/main/java/org/broad/igv/prefs/PreferencesManager.java index bce0d08f7d..dc7360ebae 100644 --- a/src/main/java/org/broad/igv/prefs/PreferencesManager.java +++ b/src/main/java/org/broad/igv/prefs/PreferencesManager.java @@ -2,6 +2,7 @@ import org.broad.igv.DirectoryManager; import org.broad.igv.Globals; +import org.broad.igv.event.IGVEvent; import org.broad.igv.event.IGVEventBus; import org.broad.igv.event.IGVEventObserver; import org.broad.igv.logging.LogManager; @@ -368,7 +369,7 @@ private synchronized void storePreferences() { } @Override - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof PreferencesChangeEvent) { storePreferences(); } diff --git a/src/main/java/org/broad/igv/sam/AlignmentDataManager.java b/src/main/java/org/broad/igv/sam/AlignmentDataManager.java index 1aaba591d2..05c8b3b332 100644 --- a/src/main/java/org/broad/igv/sam/AlignmentDataManager.java +++ b/src/main/java/org/broad/igv/sam/AlignmentDataManager.java @@ -26,6 +26,7 @@ package org.broad.igv.sam; import org.broad.igv.event.DataLoadedEvent; +import org.broad.igv.event.IGVEvent; import org.broad.igv.logging.*; import org.broad.igv.Globals; import org.broad.igv.event.IGVEventBus; @@ -94,7 +95,7 @@ public AlignmentDataManager(ResourceLocator locator, Genome genome) throws IOExc IGVEventBus.getInstance().subscribe(RefreshEvent.class, this); } - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof FrameManager.ChangeEvent) { trimCache(); } else if (event instanceof RefreshEvent) { diff --git a/src/main/java/org/broad/igv/sam/AlignmentTileLoader.java b/src/main/java/org/broad/igv/sam/AlignmentTileLoader.java index 1547bd4bfd..cde1606679 100644 --- a/src/main/java/org/broad/igv/sam/AlignmentTileLoader.java +++ b/src/main/java/org/broad/igv/sam/AlignmentTileLoader.java @@ -28,6 +28,7 @@ import htsjdk.samtools.SAMFileHeader; import htsjdk.samtools.SAMTag; import htsjdk.samtools.util.CloseableIterator; +import org.broad.igv.event.IGVEvent; import org.broad.igv.logging.*; import org.broad.igv.Globals; import org.broad.igv.prefs.IGVPreferences; @@ -380,7 +381,7 @@ public boolean isMoleculo() { } @Override - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof StopEvent) { cancel = true; reader.cancelQuery(); diff --git a/src/main/java/org/broad/igv/sam/AlignmentTrack.java b/src/main/java/org/broad/igv/sam/AlignmentTrack.java index 14c0664d04..d95711880e 100644 --- a/src/main/java/org/broad/igv/sam/AlignmentTrack.java +++ b/src/main/java/org/broad/igv/sam/AlignmentTrack.java @@ -29,6 +29,7 @@ import org.broad.igv.Globals; import org.broad.igv.event.AlignmentTrackEvent; import org.broad.igv.event.DataLoadedEvent; +import org.broad.igv.event.IGVEvent; import org.broad.igv.event.IGVEventBus; import org.broad.igv.event.IGVEventObserver; import org.broad.igv.feature.FeatureUtils; @@ -367,7 +368,7 @@ public void init() { @Override - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof FrameManager.ChangeEvent) { // Trim insertionInterval map to current frames diff --git a/src/main/java/org/broad/igv/sam/InsertionSelectionEvent.java b/src/main/java/org/broad/igv/sam/InsertionSelectionEvent.java index 35df11a526..73e61f1570 100644 --- a/src/main/java/org/broad/igv/sam/InsertionSelectionEvent.java +++ b/src/main/java/org/broad/igv/sam/InsertionSelectionEvent.java @@ -26,9 +26,11 @@ package org.broad.igv.sam; +import org.broad.igv.event.IGVEvent; + /** * Created by jrobinso on 1/12/17. */ -public record InsertionSelectionEvent(InsertionMarker insertionMarker) { +public record InsertionSelectionEvent(InsertionMarker insertionMarker) implements IGVEvent { } diff --git a/src/main/java/org/broad/igv/sashimi/SashimiPlot.java b/src/main/java/org/broad/igv/sashimi/SashimiPlot.java index c0211c34e5..cd1ef9d626 100644 --- a/src/main/java/org/broad/igv/sashimi/SashimiPlot.java +++ b/src/main/java/org/broad/igv/sashimi/SashimiPlot.java @@ -25,6 +25,7 @@ package org.broad.igv.sashimi; +import org.broad.igv.event.IGVEvent; import org.broad.igv.event.IGVEventBus; import org.broad.igv.event.IGVEventObserver; import org.broad.igv.event.ViewChange; @@ -246,7 +247,7 @@ private SashimiJunctionRenderer getRenderer(SpliceJunctionTrack spliceJunctionTr } @Override - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { repaint(); } diff --git a/src/main/java/org/broad/igv/session/Session.java b/src/main/java/org/broad/igv/session/Session.java index 43706b50ec..0f185f7e73 100644 --- a/src/main/java/org/broad/igv/session/Session.java +++ b/src/main/java/org/broad/igv/session/Session.java @@ -26,6 +26,7 @@ package org.broad.igv.session; import org.broad.igv.Globals; +import org.broad.igv.event.IGVEvent; import org.broad.igv.event.IGVEventBus; import org.broad.igv.event.IGVEventObserver; import org.broad.igv.event.ViewChange; @@ -127,7 +128,7 @@ public void reset(String path) { } - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof ViewChange) { ViewChange e = (ViewChange) event; if (e.recordHistory()) { diff --git a/src/main/java/org/broad/igv/track/DataTrack.java b/src/main/java/org/broad/igv/track/DataTrack.java index 63ea011ae0..61e579b6b6 100644 --- a/src/main/java/org/broad/igv/track/DataTrack.java +++ b/src/main/java/org/broad/igv/track/DataTrack.java @@ -33,6 +33,7 @@ */ package org.broad.igv.track; +import org.broad.igv.event.IGVEvent; import org.broad.igv.logging.*; import org.broad.igv.Globals; import org.broad.igv.event.IGVEventBus; @@ -84,7 +85,7 @@ public DataTrack(ResourceLocator locator, String id, String name) { public DataTrack() { } - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof FrameManager.ChangeEvent) { diff --git a/src/main/java/org/broad/igv/track/FeatureTrack.java b/src/main/java/org/broad/igv/track/FeatureTrack.java index 2f0df831ab..3af5ea1414 100644 --- a/src/main/java/org/broad/igv/track/FeatureTrack.java +++ b/src/main/java/org/broad/igv/track/FeatureTrack.java @@ -27,6 +27,7 @@ import htsjdk.tribble.Feature; import htsjdk.tribble.TribbleException; +import org.broad.igv.event.IGVEvent; import org.broad.igv.logging.*; import org.broad.igv.Globals; import org.broad.igv.event.DataLoadedEvent; @@ -222,7 +223,7 @@ public void unload() { /** * Called after features are finished loading, which can be asynchronous */ - public void receiveEvent(Object e) { + public void receiveEvent(IGVEvent e) { if (e instanceof DataLoadedEvent) { // DataLoadedEvent event = (DataLoadedEvent) e; // if (IGV.hasInstance()) { diff --git a/src/main/java/org/broad/igv/track/SequenceTrack.java b/src/main/java/org/broad/igv/track/SequenceTrack.java index 526e4baf49..afcfe29bbf 100644 --- a/src/main/java/org/broad/igv/track/SequenceTrack.java +++ b/src/main/java/org/broad/igv/track/SequenceTrack.java @@ -28,6 +28,7 @@ //~--- non-JDK imports -------------------------------------------------------- +import org.broad.igv.event.IGVEvent; import org.broad.igv.logging.*; import org.broad.igv.Globals; import org.broad.igv.event.IGVEventBus; @@ -132,7 +133,7 @@ public static String getReverseComplement(String sequence) { return new String(complement); } - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof FrameManager.ChangeEvent) { // Remove cache for discarded frames. This seems a rather round-about way to do it. diff --git a/src/main/java/org/broad/igv/ui/IGV.java b/src/main/java/org/broad/igv/ui/IGV.java index f5dc049a6b..e5efa1f0f6 100644 --- a/src/main/java/org/broad/igv/ui/IGV.java +++ b/src/main/java/org/broad/igv/ui/IGV.java @@ -2217,12 +2217,12 @@ public boolean waitForNotify(long timeout) { * * @param event */ - public void postEvent(Object event) { + public void postEvent(IGVEvent event) { IGVEventBus.getInstance().post(event); } - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof ViewChange || event instanceof InsertionSelectionEvent) { repaint(); } else if (event instanceof GenomeChangeEvent) { diff --git a/src/main/java/org/broad/igv/ui/IGVMenuBar.java b/src/main/java/org/broad/igv/ui/IGVMenuBar.java index 7cbb546066..68b9e264c8 100644 --- a/src/main/java/org/broad/igv/ui/IGVMenuBar.java +++ b/src/main/java/org/broad/igv/ui/IGVMenuBar.java @@ -32,11 +32,11 @@ import org.broad.igv.batch.CommandExecutor; import org.broad.igv.charts.ScatterPlotUtils; import org.broad.igv.event.GenomeChangeEvent; +import org.broad.igv.event.IGVEvent; import org.broad.igv.event.IGVEventBus; import org.broad.igv.event.IGVEventObserver; import org.broad.igv.feature.genome.GenomeManager; import org.broad.igv.feature.genome.GenomeUtils; -import org.broad.igv.prefs.IGVPreferences; import org.broad.igv.track.AttributeManager; import org.broad.igv.track.Track; import org.broad.igv.util.GoogleUtils; @@ -1163,10 +1163,10 @@ static void destroyInstance() { @Override - public void receiveEvent(final Object event) { + public void receiveEvent(final IGVEvent event) { if (event instanceof GenomeChangeEvent) { - UIUtilities.invokeOnEventThread(() -> encodeMenuItem.setVisible(EncodeFileBrowser.genomeSupported(((GenomeChangeEvent) event).genome.getId()))); + UIUtilities.invokeOnEventThread(() -> encodeMenuItem.setVisible(EncodeFileBrowser.genomeSupported(((GenomeChangeEvent) event).genome().getId()))); } } diff --git a/src/main/java/org/broad/igv/ui/commandbar/IGVCommandBar.java b/src/main/java/org/broad/igv/ui/commandbar/IGVCommandBar.java index 6968c47aab..c060215e25 100644 --- a/src/main/java/org/broad/igv/ui/commandbar/IGVCommandBar.java +++ b/src/main/java/org/broad/igv/ui/commandbar/IGVCommandBar.java @@ -280,10 +280,9 @@ private void roiToggleButtonActionPerformed(java.awt.event.ActionEvent evt) { // - public void receiveEvent(Object e) { + public void receiveEvent(IGVEvent e) { - if (e instanceof ViewChange) { - ViewChange event = (ViewChange) e; + if (e instanceof ViewChange event) { if (event.type == ViewChange.Type.ChromosomeChange || event.type == ViewChange.Type.LocusChange) { String chrName = FrameManager.getDefaultFrame().getChrName(); roiToggleButton.setEnabled(!Globals.CHR_ALL.equals(chrName)); @@ -294,10 +293,9 @@ public void receiveEvent(Object e) { } updateCurrentCoordinates(); - repaint(); // TODO Is this neccessary? - } else if (e instanceof GenomeChangeEvent) { - GenomeChangeEvent event = (GenomeChangeEvent) e; - Genome genome = event.genome; + repaint(); // TODO Is this necessary? + } else if (e instanceof GenomeChangeEvent event) { + Genome genome = event.genome(); refreshGenomeListComboBox(); chromosomeComboBox.updateChromosFromGenome(genome); String chrName = FrameManager.getDefaultFrame().getChrName(); diff --git a/src/main/java/org/broad/igv/ui/panel/CytobandPanel.java b/src/main/java/org/broad/igv/ui/panel/CytobandPanel.java index 946e8d5569..5b27b27e4e 100644 --- a/src/main/java/org/broad/igv/ui/panel/CytobandPanel.java +++ b/src/main/java/org/broad/igv/ui/panel/CytobandPanel.java @@ -166,8 +166,7 @@ public void igvMouseClicked(MouseEvent e) { referenceFrame.centerOnLocation(newLocation); } - ViewChange result = ViewChange.LocusChangeResult(referenceFrame.chrName, referenceFrame.origin, referenceFrame.getEnd()); - result.setRecordHistory(true); + ViewChange result = ViewChange.LocusChangeResult(referenceFrame.chrName, referenceFrame.origin, referenceFrame.getEnd(), true); IGVEventBus.getInstance().post(result); } finally { @@ -196,8 +195,7 @@ public void mouseReleased(MouseEvent e) { } finally { WaitCursorManager.removeWaitCursor(token); } - ViewChange result = ViewChange.LocusChangeResult(referenceFrame.chrName, referenceFrame.origin, referenceFrame.getEnd()); - result.setRecordHistory(true); + ViewChange result = ViewChange.LocusChangeResult(referenceFrame.chrName, referenceFrame.origin, referenceFrame.getEnd(), true); IGVEventBus.getInstance().post(result); } isDragging = false; diff --git a/src/main/java/org/broad/igv/ui/panel/DataPanel.java b/src/main/java/org/broad/igv/ui/panel/DataPanel.java index bce45fc33b..028344d4d8 100644 --- a/src/main/java/org/broad/igv/ui/panel/DataPanel.java +++ b/src/main/java/org/broad/igv/ui/panel/DataPanel.java @@ -34,6 +34,7 @@ package org.broad.igv.ui.panel; import com.google.common.base.Objects; +import org.broad.igv.event.IGVEvent; import org.broad.igv.logging.*; import org.broad.igv.Globals; import org.broad.igv.event.DataLoadedEvent; @@ -62,10 +63,6 @@ import java.text.DecimalFormat; import java.util.List; import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.stream.Collectors; /** * The batch panel for displaying tracks and data. A DataPanel is always associated with a ReferenceFrame. Normally @@ -100,9 +97,9 @@ public DataPanel(ReferenceFrame frame, DataPanelContainer parent) { } @Override - public void receiveEvent(Object event) { - if (event instanceof DataLoadedEvent) { - if (((DataLoadedEvent) event).referenceFrame == frame) { + public void receiveEvent(IGVEvent event) { + if (event instanceof DataLoadedEvent e) { + if (e.referenceFrame() == frame) { log.debug("Data loaded repaint " + frame); repaint(); } diff --git a/src/main/java/org/broad/igv/ui/panel/FrameManager.java b/src/main/java/org/broad/igv/ui/panel/FrameManager.java index ae0db7ec56..17cef8d895 100644 --- a/src/main/java/org/broad/igv/ui/panel/FrameManager.java +++ b/src/main/java/org/broad/igv/ui/panel/FrameManager.java @@ -26,6 +26,7 @@ package org.broad.igv.ui.panel; import org.broad.igv.event.GenomeChangeEvent; +import org.broad.igv.event.IGVEvent; import org.broad.igv.event.IGVEventBus; import org.broad.igv.event.IGVEventObserver; import org.broad.igv.feature.Locus; @@ -357,7 +358,7 @@ public static void addFrames(List newLociStrings) { @Override - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof final GenomeChangeEvent e) { Genome newGenome = e.genome(); boolean force = true; @@ -366,7 +367,7 @@ public void receiveEvent(Object event) { } - public record ChangeEvent(List frames) {} + public record ChangeEvent(List frames) implements IGVEvent {} } diff --git a/src/main/java/org/broad/igv/ui/panel/HeaderPanel.java b/src/main/java/org/broad/igv/ui/panel/HeaderPanel.java index 38efadd6c6..f9aa680844 100644 --- a/src/main/java/org/broad/igv/ui/panel/HeaderPanel.java +++ b/src/main/java/org/broad/igv/ui/panel/HeaderPanel.java @@ -35,6 +35,7 @@ package org.broad.igv.ui.panel; +import org.broad.igv.event.IGVEvent; import org.broad.igv.event.IGVEventBus; import org.broad.igv.event.IGVEventObserver; import org.broad.igv.event.ViewChange; @@ -42,7 +43,6 @@ import org.broad.igv.track.TrackMenuUtils; import org.broad.igv.ui.IGV; import org.broad.igv.ui.util.IGVMouseInputAdapter; -import org.broad.igv.ui.util.SwitchingLabelUI; import javax.swing.*; import java.awt.*; @@ -313,7 +313,7 @@ public int getSnapshotHeight(boolean batch) { } @Override - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if(label != null && frame != null) label.setText(frame.getFormattedLocusString()); } diff --git a/src/main/java/org/broad/igv/ui/panel/ReferenceFrame.java b/src/main/java/org/broad/igv/ui/panel/ReferenceFrame.java index 6cf0fb4a11..53aae53515 100644 --- a/src/main/java/org/broad/igv/ui/panel/ReferenceFrame.java +++ b/src/main/java/org/broad/igv/ui/panel/ReferenceFrame.java @@ -167,7 +167,7 @@ public void setVisible(boolean visible) { public void dragStopped() { setOrigin(Math.round(origin)); // Snap to gride - eventBus.post(ViewChange.LocusChangeResult(chrName, origin, getEnd())); + eventBus.post(ViewChange.LocusChangeResult(chrName, origin, getEnd(), false)); } public void changeGenome(Genome genome) { @@ -177,8 +177,7 @@ public void changeGenome(Genome genome) { public void changeChromosome(String chrName, boolean recordHistory) { boolean changed = setChromosomeName(chrName, false); // if (changed) { - ViewChange resultEvent = ViewChange.ChromosomeChangeResult(chrName); - resultEvent.setRecordHistory(recordHistory); + ViewChange resultEvent = ViewChange.ChromosomeChangeResult(chrName, recordHistory); eventBus.post(resultEvent); changeZoom(0); // } @@ -186,8 +185,7 @@ public void changeChromosome(String chrName, boolean recordHistory) { public void changeZoom(int newZoom) { doSetZoom(newZoom); - ViewChange result = ViewChange.LocusChangeResult(chrName, origin, getEnd()); - result.setRecordHistory(false); + ViewChange result = ViewChange.LocusChangeResult(chrName, origin, getEnd(), false); eventBus.post(result); } @@ -382,7 +380,7 @@ public void shiftOriginPixels(int delta) { double shiftBP = delta * getScale(); setOrigin(shiftBP + origin); - eventBus.post(ViewChange.LocusChangeResult(chrName, origin, getEnd())); + eventBus.post(ViewChange.LocusChangeResult(chrName, origin, getEnd(), false)); } public void centerOnLocation(String chr, double chrLocation) { @@ -395,7 +393,7 @@ public void centerOnLocation(String chr, double chrLocation) { public void centerOnLocation(double chrLocation) { double windowWidth = (widthInPixels * getScale()) / 2; setOrigin(Math.round(chrLocation - windowWidth)); - eventBus.post(ViewChange.LocusChangeResult(chrName, origin, chrLocation + windowWidth)); + eventBus.post(ViewChange.LocusChangeResult(chrName, origin, chrLocation + windowWidth, false)); } public boolean windowAtEnd() { @@ -448,7 +446,7 @@ public void jumpTo(Locus locus) { log.debug("Scale = " + scale); } - eventBus.post(ViewChange.LocusChangeResult(chrName, start, end)); + eventBus.post(ViewChange.LocusChangeResult(chrName, start, end, false)); } public double getOrigin() { diff --git a/src/main/java/org/broad/igv/ui/panel/RegionNavigatorDialog.java b/src/main/java/org/broad/igv/ui/panel/RegionNavigatorDialog.java index da7bc819df..772040615d 100644 --- a/src/main/java/org/broad/igv/ui/panel/RegionNavigatorDialog.java +++ b/src/main/java/org/broad/igv/ui/panel/RegionNavigatorDialog.java @@ -26,6 +26,7 @@ package org.broad.igv.ui.panel; +import org.broad.igv.event.IGVEvent; import org.broad.igv.logging.*; import org.broad.igv.feature.Range; import org.broad.igv.feature.RegionOfInterest; @@ -133,7 +134,7 @@ public void update(Observable observable, Object object) { synchRegions(); } - public void receiveEvent(Object e) { + public void receiveEvent(IGVEvent e) { synchRegions(); } diff --git a/src/main/java/org/broad/igv/ui/util/ApplicationStatusBar.java b/src/main/java/org/broad/igv/ui/util/ApplicationStatusBar.java index 4eb3b4f8f5..4c6c9b966a 100644 --- a/src/main/java/org/broad/igv/ui/util/ApplicationStatusBar.java +++ b/src/main/java/org/broad/igv/ui/util/ApplicationStatusBar.java @@ -27,6 +27,7 @@ package org.broad.igv.ui.util; import com.jidesoft.swing.JideBoxLayout; +import org.broad.igv.event.IGVEvent; import org.broad.igv.event.StopEvent; import org.broad.igv.logging.*; import org.broad.igv.oauth.OAuthProvider; @@ -34,13 +35,10 @@ import org.broad.igv.ui.FontManager; import org.broad.igv.event.IGVEventBus; import org.broad.igv.event.IGVEventObserver; -import org.broad.igv.ui.IGV; //import org.broad.igv.event.StopEvent; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.text.NumberFormat; import java.util.TimerTask; @@ -157,7 +155,7 @@ public void enableStopButton(boolean enable) { } @Override - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof OAuthProvider.AuthStateEvent) { String msg = ""; diff --git a/src/main/java/org/broad/igv/variant/VariantTrack.java b/src/main/java/org/broad/igv/variant/VariantTrack.java index 97910f08d7..1e3633edf1 100644 --- a/src/main/java/org/broad/igv/variant/VariantTrack.java +++ b/src/main/java/org/broad/igv/variant/VariantTrack.java @@ -31,6 +31,7 @@ import htsjdk.tribble.Feature; import htsjdk.variant.variantcontext.GenotypeType; import org.broad.igv.Globals; +import org.broad.igv.event.IGVEvent; import org.broad.igv.event.IGVEventBus; import org.broad.igv.event.IGVEventObserver; import org.broad.igv.event.TrackGroupEvent; @@ -1190,7 +1191,7 @@ public void setSquishedHeight(int squishedHeight) { } @Override - public void receiveEvent(Object event) { + public void receiveEvent(IGVEvent event) { if (event instanceof TrackGroupEvent) { setupGroupsFromAttributes(); }