Skip to content

Commit

Permalink
Make IGV events all implement sealed interface IGVEvent
Browse files Browse the repository at this point in the history
This isn't really a functional change but makes it a bit easier to find/understand what
event types are available.
  • Loading branch information
lbergelson committed Oct 31, 2023
1 parent 144cd07 commit 6421884
Show file tree
Hide file tree
Showing 35 changed files with 93 additions and 63 deletions.
1 change: 1 addition & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/AlignmentTrackEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/DataLoadedEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
* User: jacob
* Date: 2013-Feb-06
*/
public record DataLoadedEvent(ReferenceFrame referenceFrame) {}
public record DataLoadedEvent(ReferenceFrame referenceFrame) implements IGVEvent {}
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/GenomeChangeEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
/**
* Created by jrobinso on 1/7/17.
*/
public record GenomeChangeEvent(Genome genome) {}
public record GenomeChangeEvent(Genome genome) implements IGVEvent {}
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/GenomeResetEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
/**
* Created by jrobinso on 2/7/17.
*/
public class GenomeResetEvent {
public final class GenomeResetEvent implements IGVEvent {
}
23 changes: 23 additions & 0 deletions src/main/java/org/broad/igv/event/IGVEvent.java
Original file line number Diff line number Diff line change
@@ -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 {

}
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/IGVEventBus.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public synchronized void unsubscribe(IGVEventObserver observer) {
}
}

public void post(Object event) {
public void post(IGVEvent event) {
Set<IGVEventObserver> observerSet = observerMap.get(event.getClass());
if (observerSet != null) {
// Make a copy in case original is modified during loop
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/IGVEventObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
*/
public interface IGVEventObserver {

void receiveEvent(Object event);
void receiveEvent(IGVEvent event);

}
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/RefreshEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
/**
* Created by jrobinso on 6/24/17.
*/
public class RefreshEvent {
public final class RefreshEvent implements IGVEvent {
}
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/StopEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
/**
* Created by jrobinso on 6/24/17.
*/
public class StopEvent {
public final class StopEvent implements IGVEvent{
}
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/TrackGroupEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
* @author Jim Robinson
* @date 10/28/11
*/
public class TrackGroupEvent {
public final class TrackGroupEvent implements IGVEvent {
}
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/event/ViewChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/oauth/OAuthProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/prefs/PreferencesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -368,7 +369,7 @@ private synchronized void storePreferences() {
}

@Override
public void receiveEvent(Object event) {
public void receiveEvent(IGVEvent event) {
if (event instanceof PreferencesChangeEvent) {
storePreferences();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/sam/AlignmentDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/sam/AlignmentTileLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/sam/AlignmentTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/broad/igv/sam/InsertionSelectionEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

}
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/sashimi/SashimiPlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -246,7 +247,7 @@ private SashimiJunctionRenderer getRenderer(SpliceJunctionTrack spliceJunctionTr
}

@Override
public void receiveEvent(Object event) {
public void receiveEvent(IGVEvent event) {
repaint();
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/session/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/track/DataTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/track/FeatureTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/track/SequenceTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/broad/igv/ui/IGV.java
Original file line number Diff line number Diff line change
Expand Up @@ -2152,12 +2152,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) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/broad/igv/ui/IGVMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())));
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/broad/igv/ui/commandbar/IGVCommandBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,9 @@ private void roiToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {

//</editor-fold>

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));
Expand All @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/broad/igv/ui/panel/CytobandPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 6421884

Please sign in to comment.