use of org.eclipse.tracecompass.tmf.ui.viewers.IImageSave in project tracecompass by tracecompass.
the class SaveImageUtil method createSaveAction.
/**
* Create a save action to save the contol image
*
* @param name
* default file name
* @param controlSupplier
* the supplier of the control to take a picture of
* @return the action.
*/
public static Action createSaveAction(@Nullable String name, Supplier<@Nullable IImageSave> controlSupplier) {
Action saveAction = new Action(Messages.AbstractTimeGraphView_ExportImageActionText) {
@Override
public void run() {
IImageSave iImageSave = controlSupplier.get();
if (iImageSave == null) {
return;
}
FileDialog dialog = TmfFileDialogFactory.create(new Shell(), SWT.SAVE);
// the following arrays must be in the same order
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String[] filters = { "*.png", "*.gif", "*.jpg", "*.bmp" };
int[] filterTypes = { SWT.IMAGE_PNG, SWT.IMAGE_GIF, SWT.IMAGE_JPEG, SWT.IMAGE_BMP };
dialog.setFilterExtensions(filters);
// In case the user doesn't click anything.
dialog.setFilterIndex(0);
// $NON-NLS-1$ //$NON-NLS-2$
dialog.setFileName((name == null ? "Untitled" : name) + ".png");
String ret = dialog.open();
if ((ret != null) && !ret.isEmpty()) {
int index = dialog.getFilterIndex();
iImageSave.saveImage(ret, filterTypes[index]);
}
}
@Override
public boolean isEnabled() {
IImageSave iImageSave = controlSupplier.get();
if (iImageSave == null) {
return false;
}
return super.isEnabled();
}
};
saveAction.setToolTipText(Messages.AbstractTimeGraphView_ExportImageToolTipText);
return saveAction;
}
use of org.eclipse.tracecompass.tmf.ui.viewers.IImageSave in project tracecompass by tracecompass.
the class LamiReportView method getSuppliers.
private List<Supplier<@Nullable IImageSave>> getSuppliers() {
List<Supplier<@Nullable IImageSave>> suppliers = new ArrayList<>();
LamiReportViewTabPage selectedPage = getCurrentSelectedPage();
if (selectedPage == null) {
return Collections.emptyList();
}
List<LamiViewerControl> plots = selectedPage.getCustomGraphViewerControls();
for (int i = 0; i < plots.size(); i++) {
IImageSave iis = fImageProvider.apply(i);
if (iis != null) {
suppliers.add(() -> iis);
}
}
return suppliers;
}
Aggregations