Skip to content

Commit 30d6578

Browse files
committed
Open PDF viewer when exporting legend
1 parent 813856d commit 30d6578

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/heatmap/ExportPDFAction.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.baderlab.csplugins.enrichmentmap.view.heatmap;
22

3-
import java.awt.Desktop;
43
import java.awt.event.ActionEvent;
54
import java.io.File;
65
import java.util.Optional;
@@ -11,11 +10,10 @@
1110
import javax.swing.JTable;
1211

1312
import org.baderlab.csplugins.enrichmentmap.view.util.FileBrowser;
13+
import org.baderlab.csplugins.enrichmentmap.view.util.OpenPDFViewerTask;
1414
import org.cytoscape.util.swing.FileUtil;
15-
import org.cytoscape.work.AbstractTask;
1615
import org.cytoscape.work.Task;
1716
import org.cytoscape.work.TaskIterator;
18-
import org.cytoscape.work.TaskMonitor;
1917
import org.cytoscape.work.swing.DialogTaskManager;
2018

2119
import com.google.inject.Inject;
@@ -48,25 +46,12 @@ public void actionPerformed(ActionEvent e) {
4846
Optional<File> file = FileBrowser.promptForPdfExport(fileUtil, jframeProvider.get());
4947
if(file.isPresent()) {
5048
ExportPDFTask exportPdfTask = new ExportPDFTask(file.get(), table, rankingSupplier.get());
51-
Task openPdfViewerTask = getOpenPdfViewerTask(file.get());
49+
Task openPdfViewerTask = new OpenPDFViewerTask(file.get());
5250
dialogTaskManager.execute(new TaskIterator(exportPdfTask, openPdfViewerTask));
5351
}
5452
}
5553

5654

57-
private static Task getOpenPdfViewerTask(File file) {
58-
return new AbstractTask() {
59-
@Override
60-
public void run(TaskMonitor taskMonitor) {
61-
try {
62-
if(Desktop.isDesktopSupported()) {
63-
Desktop.getDesktop().open(file);
64-
}
65-
} catch(Exception e) { } // ignore, just make best attempt to open the viewer
66-
}
67-
};
68-
}
69-
7055
}
7156

7257

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/legend/LegendPanelMediator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import org.baderlab.csplugins.enrichmentmap.model.EMDataSet;
2323
import org.baderlab.csplugins.enrichmentmap.style.EMStyleOptions;
2424
import org.baderlab.csplugins.enrichmentmap.view.util.FileBrowser;
25+
import org.baderlab.csplugins.enrichmentmap.view.util.OpenPDFViewerTask;
2526
import org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil;
2627
import org.cytoscape.application.swing.CySwingApplication;
2728
import org.cytoscape.util.swing.FileUtil;
2829
import org.cytoscape.util.swing.IconManager;
2930
import org.cytoscape.util.swing.LookAndFeelUtil;
31+
import org.cytoscape.work.Task;
3032
import org.cytoscape.work.TaskIterator;
3133
import org.cytoscape.work.swing.DialogTaskManager;
3234

@@ -128,8 +130,9 @@ private void updateDialog(EMStyleOptions options, Collection<EMDataSet> filtered
128130
private void exportPDF() {
129131
Optional<File> file = FileBrowser.promptForPdfExport(fileUtil, swingApplication.getJFrame());
130132
if(file.isPresent()) {
131-
ExportLegendPDFTask task = new ExportLegendPDFTask(file.get(), legendPanelProvider.get());
132-
dialogTaskManager.execute(new TaskIterator(task));
133+
ExportLegendPDFTask exportTask = new ExportLegendPDFTask(file.get(), legendPanelProvider.get());
134+
Task openPdfViewerTask = new OpenPDFViewerTask(file.get());
135+
dialogTaskManager.execute(new TaskIterator(exportTask, openPdfViewerTask));
133136
}
134137
}
135138

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.baderlab.csplugins.enrichmentmap.view.util;
2+
3+
import java.awt.Desktop;
4+
import java.io.File;
5+
import java.util.Objects;
6+
7+
import org.cytoscape.work.AbstractTask;
8+
import org.cytoscape.work.TaskMonitor;
9+
10+
public class OpenPDFViewerTask extends AbstractTask {
11+
12+
private final File file;
13+
14+
public OpenPDFViewerTask(File file) {
15+
this.file = Objects.requireNonNull(file);
16+
}
17+
18+
@Override
19+
public void run(TaskMonitor tm) throws Exception {
20+
try {
21+
if(Desktop.isDesktopSupported()) {
22+
Desktop.getDesktop().open(file);
23+
}
24+
} catch(Exception e) {
25+
// ignore, just make best attempt to open the viewer
26+
}
27+
}
28+
29+
}

0 commit comments

Comments
 (0)