1 /*
2  * CopyPlotToClipboardDesktopDialogBase.java
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 package org.rstudio.studio.client.workbench.exportplot.clipboard;
16 
17 import org.rstudio.core.client.widget.Operation;
18 import org.rstudio.core.client.widget.OperationWithInput;
19 import org.rstudio.core.client.widget.ThemedButton;
20 import org.rstudio.studio.client.workbench.exportplot.ExportPlotDialog;
21 import org.rstudio.studio.client.workbench.exportplot.ExportPlotPreviewer;
22 import org.rstudio.studio.client.workbench.exportplot.model.ExportPlotOptions;
23 
24 import com.google.gwt.event.dom.client.ClickEvent;
25 import com.google.gwt.event.dom.client.ClickHandler;
26 
27 public abstract class CopyPlotToClipboardDesktopDialogBase extends ExportPlotDialog
28 {
CopyPlotToClipboardDesktopDialogBase( final ExportPlotOptions options, ExportPlotPreviewer previewer, final OperationWithInput<ExportPlotOptions> onClose)29    public CopyPlotToClipboardDesktopDialogBase(
30                            final ExportPlotOptions options,
31                            ExportPlotPreviewer previewer,
32                            final OperationWithInput<ExportPlotOptions> onClose)
33    {
34       super(options, previewer);
35 
36       setText("Copy Plot to Clipboard");
37 
38       ThemedButton copyButton = new ThemedButton("Copy Plot",
39             new ClickHandler() {
40          public void onClick(ClickEvent event)
41          {
42             // do the copy
43             performCopy(new Operation() {
44 
45                @Override
46                public void execute()
47                {
48                   // save options
49                   onClose.execute(getCurrentOptions(options));
50 
51                   // close dialog
52                   closeDialog();
53                }
54             });
55          }
56       });
57 
58       addOkButton(copyButton);
59       addCancelButton();
60    }
61 
62 
performCopy(Operation onCompleted)63    protected void performCopy(Operation onCompleted)
64    {
65       copyAsBitmap(onCompleted);
66    }
67 
copyAsBitmap(final Operation onCompleted)68    protected abstract void copyAsBitmap(final Operation onCompleted);
69 }
70