Search in sources :

Example 1 with IImageSave

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;
}
Also used : Action(org.eclipse.jface.action.Action) Shell(org.eclipse.swt.widgets.Shell) IImageSave(org.eclipse.tracecompass.tmf.ui.viewers.IImageSave) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 2 with IImageSave

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;
}
Also used : IImageSave(org.eclipse.tracecompass.tmf.ui.viewers.IImageSave) ArrayList(java.util.ArrayList) Supplier(java.util.function.Supplier) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

IImageSave (org.eclipse.tracecompass.tmf.ui.viewers.IImageSave)2 ArrayList (java.util.ArrayList)1 Supplier (java.util.function.Supplier)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 Action (org.eclipse.jface.action.Action)1 FileDialog (org.eclipse.swt.widgets.FileDialog)1 Shell (org.eclipse.swt.widgets.Shell)1