Skip to content

Commit

Permalink
Add right-click menu option to remove empty track panels
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Jul 25, 2024
1 parent e5e6254 commit d4e05b7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 45 deletions.
8 changes: 8 additions & 0 deletions src/main/java/org/broad/igv/ui/IGV.java
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,14 @@ public void removeDataPanel(String name) {
contentPane.getMainPanel().removeDataPanel(name);
}

public void removeTrackPanel(TrackPanel trackPanel) {
contentPane.getMainPanel().removeTrackPanel(trackPanel);
}

public boolean panelIsRemovable(TrackPanel trackPanel) {
return contentPane.getMainPanel().panelIsRemovable(trackPanel);
}

public MainPanel getMainPanel() {
return contentPane.getMainPanel();
}
Expand Down
25 changes: 16 additions & 9 deletions src/main/java/org/broad/igv/ui/panel/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,30 @@ public void removeEmptyDataPanels() {

public void removeDataPanel(String name) {

TrackPanelScrollPane sp = null;
for (TrackPanel tp : getTrackPanels()) {
if (name.equals(tp.getName())) {
sp = tp.getScrollPane();
break;
removeTrackPanel(tp);
return;
}
}
}

public void removeTrackPanel(TrackPanel trackPanel) {
// Don't remove the "special" panes
if (sp == dataTrackScrollPane || sp == featureTrackScrollPane) {
return;
}
if (sp != null) {
centerSplitPane.remove(sp);
TrackNamePanel.removeDropListenerFor(sp.getNamePanel());
if (panelIsRemovable(trackPanel)) {
TrackPanelScrollPane sp = trackPanel.getScrollPane();
if (sp != null) {
centerSplitPane.remove(sp);
TrackNamePanel.removeDropListenerFor(sp.getNamePanel());
centerSplitPane.revalidate();
}
}
}

public boolean panelIsRemovable(TrackPanel trackPanel) {
return trackPanel.getScrollPane() != dataTrackScrollPane && trackPanel.getScrollPane() != featureTrackScrollPane;
}

public void updatePanelDimensions() {
Insets insets = applicationHeaderPanel.getInsets();
namePanelX = insets.left;
Expand Down
85 changes: 49 additions & 36 deletions src/main/java/org/broad/igv/ui/panel/TrackPanelComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
import org.broad.igv.track.Track;
import org.broad.igv.track.TrackClickEvent;
import org.broad.igv.track.TrackMenuUtils;
import org.broad.igv.ui.FontManager;
import org.broad.igv.ui.IGV;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
Expand Down Expand Up @@ -176,57 +178,68 @@ protected void openPopupMenu(TrackClickEvent te) {
protected void openPopupMenu(TrackClickEvent te, List<Component> extraItems) {

MouseEvent e = te.getMouseEvent();
IGVPopupMenu menu = null;

final Collection<Track> selectedTracks = getSelectedTracks();
if (selectedTracks.isEmpty()) {
return;
}
// If this panel is empty (no tracks), and is removable, present option to remove it
if (getAllTracks().size() == 0 && IGV.getInstance().panelIsRemovable(getTrackPanel())) {
menu = new IGVPopupMenu();
JMenuItem item = new JMenuItem("Remove panel");
item.addActionListener(e12 -> {
IGV.getInstance().removeTrackPanel(getTrackPanel());
});
menu.add(item);
}
} else {

IGVPopupMenu menu = null;

// If a single track is selected, give it an opportunity to provide the popup menu
if (selectedTracks.size() == 1) {
Track track = selectedTracks.iterator().next();
menu = track.getPopupMenu(te);
}
// If a single track is selected, give it an opportunity to provide the popup menu
if (selectedTracks.size() == 1) {
Track track = selectedTracks.iterator().next();
menu = track.getPopupMenu(te);
}

// If still no menu, create a generic one with common items
if (menu == null) {
String title = getPopupMenuTitle(e.getX(), e.getY());
menu = TrackMenuUtils.getPopupMenu(selectedTracks, title, te);
}
// If still no menu, create a generic one with common items
if (menu == null) {
String title = getPopupMenuTitle(e.getX(), e.getY());
menu = TrackMenuUtils.getPopupMenu(selectedTracks, title, te);
}

// Add additional items, if any
if (extraItems != null) {
menu.addSeparator();
for (Component item : extraItems) {
menu.add(item);
// Add additional items, if any
if (extraItems != null) {
menu.addSeparator();
for (Component item : extraItems) {
menu.add(item);
}
}
}

if (menu.includeStandardItems()) {
if (menu.includeStandardItems()) {

TrackMenuUtils.addPluginItems(menu, selectedTracks, te);
TrackMenuUtils.addPluginItems(menu, selectedTracks, te);

// Add saveImage items
menu.addSeparator();
JMenuItem savePng = new JMenuItem("Save PNG image...");
savePng.addActionListener(e1 -> saveImage("png"));
menu.add(savePng);
JMenuItem saveSvg = new JMenuItem("Save SVG image...");
saveSvg.addActionListener(e1 -> saveImage("svg"));
menu.add(saveSvg);
// Add saveImage items
menu.addSeparator();
JMenuItem savePng = new JMenuItem("Save PNG image...");
savePng.addActionListener(e1 -> saveImage("png"));
menu.add(savePng);
JMenuItem saveSvg = new JMenuItem("Save SVG image...");
saveSvg.addActionListener(e1 -> saveImage("svg"));
menu.add(saveSvg);

// Add export features
ReferenceFrame frame = FrameManager.getDefaultFrame();
JMenuItem exportFeats = TrackMenuUtils.getExportFeatures(selectedTracks, frame);
if (exportFeats != null) menu.add(exportFeats);
// Add export features
ReferenceFrame frame = FrameManager.getDefaultFrame();
JMenuItem exportFeats = TrackMenuUtils.getExportFeatures(selectedTracks, frame);
if (exportFeats != null) menu.add(exportFeats);

menu.addSeparator();
menu.add(TrackMenuUtils.getRemoveMenuItem(selectedTracks));
menu.addSeparator();
menu.add(TrackMenuUtils.getRemoveMenuItem(selectedTracks));
}
}

menu.show(e.getComponent(), e.getX(), e.getY());
if(menu != null) {
menu.show(e.getComponent(), e.getX(), e.getY());
}

}

Expand Down

0 comments on commit d4e05b7

Please sign in to comment.