use of org.eclipse.swt.dnd.ImageTransfer in project dbeaver by serge-rider.
the class GISLeafletViewer method updateToolbar.
private void updateToolbar() {
toolBarManager.removeAll();
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_open, DBeaverIcons.getImageDescriptor(UIIcon.BROWSER)) {
@Override
public void run() {
UIUtils.launchProgram(scriptFile.getAbsolutePath());
}
});
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_copy_as, DBeaverIcons.getImageDescriptor(UIIcon.PICTURE)) {
@Override
public void run() {
Image image = new Image(Display.getDefault(), browser.getBounds());
GC gc = new GC(image);
try {
browser.print(gc);
} finally {
gc.dispose();
}
ImageTransfer imageTransfer = ImageTransfer.getInstance();
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object[] { image.getImageData() }, new Transfer[] { imageTransfer });
}
});
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_save_as, DBeaverIcons.getImageDescriptor(UIIcon.PICTURE_SAVE)) {
@Override
public void run() {
final Shell shell = browser.getShell();
FileDialog saveDialog = new FileDialog(shell, SWT.SAVE);
String[] extensions = new String[SUPPORTED_FORMATS.length];
String[] filterNames = new String[SUPPORTED_FORMATS.length];
for (int i = 0; i < SUPPORTED_FORMATS.length; i++) {
extensions[i] = "*." + SUPPORTED_FORMATS[i];
filterNames[i] = SUPPORTED_FORMATS[i].toUpperCase() + " (*." + SUPPORTED_FORMATS[i] + ")";
}
saveDialog.setFilterExtensions(extensions);
saveDialog.setFilterNames(filterNames);
String filePath = DialogUtils.openFileDialog(saveDialog);
if (filePath == null) {
return;
}
int imageType = SWT.IMAGE_BMP;
{
String filePathLower = filePath.toLowerCase();
if (filePathLower.endsWith(".png")) {
imageType = SWT.IMAGE_PNG;
} else if (filePathLower.endsWith(".gif")) {
imageType = SWT.IMAGE_GIF;
}
}
Image image = new Image(Display.getDefault(), browser.getBounds());
GC gc = new GC(image);
try {
browser.print(gc);
} finally {
gc.dispose();
}
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[1];
imageLoader.data[0] = image.getImageData();
File outFile = new File(filePath);
try (OutputStream fos = new FileOutputStream(outFile)) {
imageLoader.save(fos, imageType);
} catch (IOException e) {
DBWorkbench.getPlatformUI().showError("Image save error", "Error saving as picture", e);
}
UIUtils.launchProgram(outFile.getAbsolutePath());
}
});
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_print, DBeaverIcons.getImageDescriptor(UIIcon.PRINT)) {
@Override
public void run() {
GC gc = new GC(browser.getDisplay());
try {
browser.execute("javascript:window.print();");
} finally {
gc.dispose();
}
}
});
toolBarManager.add(new Separator());
Action crsSelectorAction = new SelectCRSAction(this);
toolBarManager.add(ActionUtils.makeActionContribution(crsSelectorAction, true));
Action tilesSelectorAction = new SelectTilesAction(this);
toolBarManager.add(ActionUtils.makeActionContribution(tilesSelectorAction, true));
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_flip, Action.AS_CHECK_BOX) {
{
setToolTipText(GISMessages.panel_leaflet_viewer_tool_bar_action_tool_tip_text_flip);
setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.LINK_TO_EDITOR));
}
@Override
public boolean isChecked() {
return flipCoordinates;
}
@Override
public void run() {
flipCoordinates = !flipCoordinates;
try {
reloadGeometryData(lastValue, true);
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Render error", "Error rendering geometry", e);
}
saveAttributeSettings();
updateToolbar();
}
});
toolBarManager.add(new Separator());
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_show_hide, Action.AS_CHECK_BOX) {
{
setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.PALETTE));
}
@Override
public boolean isChecked() {
return toolsVisible;
}
@Override
public void run() {
toolsVisible = !toolsVisible;
updateControlsVisibility();
updateToolbar();
}
});
toolBarManager.update(true);
}
use of org.eclipse.swt.dnd.ImageTransfer in project dbeaver by dbeaver.
the class BaseChartComposite method doCopyToClipboard.
protected void doCopyToClipboard() {
Image image = new Image(Display.getDefault(), this.getBounds());
GC gc = new GC(image);
try {
this.print(gc);
} finally {
gc.dispose();
}
ImageTransfer imageTransfer = ImageTransfer.getInstance();
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object[] { image.getImageData() }, new Transfer[] { imageTransfer });
}
use of org.eclipse.swt.dnd.ImageTransfer in project dbeaver by dbeaver.
the class GISLeafletViewer method updateToolbar.
private void updateToolbar() {
toolBarManager.removeAll();
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_open, DBeaverIcons.getImageDescriptor(UIIcon.BROWSER)) {
@Override
public void run() {
UIUtils.launchProgram(scriptFile.getAbsolutePath());
}
});
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_copy_as, DBeaverIcons.getImageDescriptor(UIIcon.PICTURE)) {
@Override
public void run() {
Image image = new Image(Display.getDefault(), browser.getBounds());
GC gc = new GC(image);
try {
browser.print(gc);
} finally {
gc.dispose();
}
ImageTransfer imageTransfer = ImageTransfer.getInstance();
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object[] { image.getImageData() }, new Transfer[] { imageTransfer });
}
});
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_save_as, DBeaverIcons.getImageDescriptor(UIIcon.PICTURE_SAVE)) {
@Override
public void run() {
final Shell shell = browser.getShell();
FileDialog saveDialog = new FileDialog(shell, SWT.SAVE);
String[] extensions = new String[SUPPORTED_FORMATS.length];
String[] filterNames = new String[SUPPORTED_FORMATS.length];
for (int i = 0; i < SUPPORTED_FORMATS.length; i++) {
extensions[i] = "*." + SUPPORTED_FORMATS[i];
filterNames[i] = SUPPORTED_FORMATS[i].toUpperCase() + " (*." + SUPPORTED_FORMATS[i] + ")";
}
saveDialog.setFilterExtensions(extensions);
saveDialog.setFilterNames(filterNames);
String filePath = DialogUtils.openFileDialog(saveDialog);
if (filePath == null) {
return;
}
int imageType = SWT.IMAGE_BMP;
{
String filePathLower = filePath.toLowerCase();
if (filePathLower.endsWith(".png")) {
imageType = SWT.IMAGE_PNG;
} else if (filePathLower.endsWith(".gif")) {
imageType = SWT.IMAGE_GIF;
}
}
Image image = new Image(Display.getDefault(), browser.getBounds());
GC gc = new GC(image);
try {
browser.print(gc);
} finally {
gc.dispose();
}
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[1];
imageLoader.data[0] = image.getImageData();
File outFile = new File(filePath);
try (OutputStream fos = new FileOutputStream(outFile)) {
imageLoader.save(fos, imageType);
} catch (IOException e) {
DBWorkbench.getPlatformUI().showError("Image save error", "Error saving as picture", e);
}
UIUtils.launchProgram(outFile.getAbsolutePath());
}
});
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_print, DBeaverIcons.getImageDescriptor(UIIcon.PRINT)) {
@Override
public void run() {
GC gc = new GC(browser.getDisplay());
try {
browser.execute("javascript:window.print();");
} finally {
gc.dispose();
}
}
});
toolBarManager.add(new Separator());
Action crsSelectorAction = new SelectCRSAction(this);
toolBarManager.add(ActionUtils.makeActionContribution(crsSelectorAction, true));
Action tilesSelectorAction = new SelectTilesAction(this);
toolBarManager.add(ActionUtils.makeActionContribution(tilesSelectorAction, true));
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_flip, Action.AS_CHECK_BOX) {
{
setToolTipText(GISMessages.panel_leaflet_viewer_tool_bar_action_tool_tip_text_flip);
setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.LINK_TO_EDITOR));
}
@Override
public boolean isChecked() {
return flipCoordinates;
}
@Override
public void run() {
flipCoordinates = !flipCoordinates;
try {
reloadGeometryData(lastValue, true);
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Render error", "Error rendering geometry", e);
}
saveAttributeSettings();
updateToolbar();
}
});
toolBarManager.add(new Separator());
toolBarManager.add(new Action(GISMessages.panel_leaflet_viewer_tool_bar_action_text_show_hide, Action.AS_CHECK_BOX) {
{
setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.PALETTE));
}
@Override
public boolean isChecked() {
return toolsVisible;
}
@Override
public void run() {
toolsVisible = !toolsVisible;
updateControlsVisibility();
updateToolbar();
}
});
toolBarManager.update(true);
}
use of org.eclipse.swt.dnd.ImageTransfer in project eclipse.platform.swt by eclipse.
the class ClipboardExample method createImageTransfer.
void createImageTransfer(Composite copyParent, Composite pasteParent) {
final Image[] copyImage = new Image[] { null };
Label l = new Label(copyParent, SWT.NONE);
// $NON-NLS-1$
l.setText("ImageTransfer:");
GridData data = new GridData();
data.verticalSpan = 2;
l.setLayoutData(data);
final Canvas copyImageCanvas = new Canvas(copyParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
data = new GridData(GridData.FILL_BOTH);
data.verticalSpan = 2;
data.widthHint = HSIZE;
data.heightHint = VSIZE;
copyImageCanvas.setLayoutData(data);
final Point copyOrigin = new Point(0, 0);
final ScrollBar copyHBar = copyImageCanvas.getHorizontalBar();
copyHBar.setEnabled(false);
copyHBar.addListener(SWT.Selection, e -> {
if (copyImage[0] != null) {
int hSelection = copyHBar.getSelection();
int destX = -hSelection - copyOrigin.x;
Rectangle rect = copyImage[0].getBounds();
copyImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
copyOrigin.x = -hSelection;
}
});
final ScrollBar copyVBar = copyImageCanvas.getVerticalBar();
copyVBar.setEnabled(false);
copyVBar.addListener(SWT.Selection, e -> {
if (copyImage[0] != null) {
int vSelection = copyVBar.getSelection();
int destY = -vSelection - copyOrigin.y;
Rectangle rect = copyImage[0].getBounds();
copyImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
copyOrigin.y = -vSelection;
}
});
copyImageCanvas.addListener(SWT.Paint, e -> {
if (copyImage[0] != null) {
GC gc = e.gc;
gc.drawImage(copyImage[0], copyOrigin.x, copyOrigin.y);
Rectangle rect = copyImage[0].getBounds();
Rectangle client = copyImageCanvas.getClientArea();
int marginWidth = client.width - rect.width;
if (marginWidth > 0) {
gc.fillRectangle(rect.width, 0, marginWidth, client.height);
}
int marginHeight = client.height - rect.height;
if (marginHeight > 0) {
gc.fillRectangle(0, rect.height, client.width, marginHeight);
}
gc.dispose();
}
});
Button openButton = new Button(copyParent, SWT.PUSH);
openButton.setText("Open Image");
openButton.addSelectionListener(widgetSelectedAdapter(e -> {
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setText("Open an image file or cancel");
String string = dialog.open();
if (string != null) {
if (copyImage[0] != null) {
System.out.println("CopyImage");
copyImage[0].dispose();
}
copyImage[0] = new Image(e.display, string);
copyVBar.setEnabled(true);
copyHBar.setEnabled(true);
copyOrigin.x = 0;
copyOrigin.y = 0;
Rectangle rect = copyImage[0].getBounds();
Rectangle client = copyImageCanvas.getClientArea();
copyHBar.setMaximum(rect.width);
copyVBar.setMaximum(rect.height);
copyHBar.setThumb(Math.min(rect.width, client.width));
copyVBar.setThumb(Math.min(rect.height, client.height));
copyImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
copyVBar.setSelection(0);
copyHBar.setSelection(0);
copyImageCanvas.redraw();
}
}));
Button b = new Button(copyParent, SWT.PUSH);
b.setText("Copy");
b.addSelectionListener(widgetSelectedAdapter(e -> {
if (copyImage[0] != null) {
status.setText("");
// Fetch ImageData at current zoom and save in the clip-board.
clipboard.setContents(new Object[] { copyImage[0].getImageDataAtCurrentZoom() }, new Transfer[] { ImageTransfer.getInstance() });
} else {
status.setText("No image to copy");
}
}));
final Image[] pasteImage = new Image[] { null };
l = new Label(pasteParent, SWT.NONE);
l.setText("ImageTransfer:");
final Canvas pasteImageCanvas = new Canvas(pasteParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
data = new GridData(GridData.FILL_BOTH);
data.widthHint = HSIZE;
data.heightHint = VSIZE;
pasteImageCanvas.setLayoutData(data);
final Point pasteOrigin = new Point(0, 0);
final ScrollBar pasteHBar = pasteImageCanvas.getHorizontalBar();
pasteHBar.setEnabled(false);
pasteHBar.addListener(SWT.Selection, e -> {
if (pasteImage[0] != null) {
int hSelection = pasteHBar.getSelection();
int destX = -hSelection - pasteOrigin.x;
Rectangle rect = pasteImage[0].getBounds();
pasteImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
pasteOrigin.x = -hSelection;
}
});
final ScrollBar pasteVBar = pasteImageCanvas.getVerticalBar();
pasteVBar.setEnabled(false);
pasteVBar.addListener(SWT.Selection, e -> {
if (pasteImage[0] != null) {
int vSelection = pasteVBar.getSelection();
int destY = -vSelection - pasteOrigin.y;
Rectangle rect = pasteImage[0].getBounds();
pasteImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
pasteOrigin.y = -vSelection;
}
});
pasteImageCanvas.addListener(SWT.Paint, e -> {
if (pasteImage[0] != null) {
GC gc = e.gc;
gc.drawImage(pasteImage[0], pasteOrigin.x, pasteOrigin.y);
Rectangle rect = pasteImage[0].getBounds();
Rectangle client = pasteImageCanvas.getClientArea();
int marginWidth = client.width - rect.width;
if (marginWidth > 0) {
gc.fillRectangle(rect.width, 0, marginWidth, client.height);
}
int marginHeight = client.height - rect.height;
if (marginHeight > 0) {
gc.fillRectangle(0, rect.height, client.width, marginHeight);
}
}
});
b = new Button(pasteParent, SWT.PUSH);
b.setText("Paste");
b.addSelectionListener(widgetSelectedAdapter(e -> {
ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance());
if (imageData != null) {
if (pasteImage[0] != null) {
System.out.println("PasteImage");
pasteImage[0].dispose();
}
status.setText("");
// Consume the ImageData at current zoom as-is.
pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData));
pasteVBar.setEnabled(true);
pasteHBar.setEnabled(true);
pasteOrigin.x = 0;
pasteOrigin.y = 0;
Rectangle rect = pasteImage[0].getBounds();
Rectangle client = pasteImageCanvas.getClientArea();
pasteHBar.setMaximum(rect.width);
pasteVBar.setMaximum(rect.height);
pasteHBar.setThumb(Math.min(rect.width, client.width));
pasteVBar.setThumb(Math.min(rect.height, client.height));
pasteImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true);
pasteVBar.setSelection(0);
pasteHBar.setSelection(0);
pasteImageCanvas.redraw();
} else {
status.setText("No image to paste");
}
}));
}
use of org.eclipse.swt.dnd.ImageTransfer in project dbeaver by serge-rider.
the class BaseChartComposite method doCopyToClipboard.
protected void doCopyToClipboard() {
Image image = new Image(Display.getDefault(), this.getBounds());
GC gc = new GC(image);
try {
this.print(gc);
} finally {
gc.dispose();
}
ImageTransfer imageTransfer = ImageTransfer.getInstance();
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object[] { image.getImageData() }, new Transfer[] { imageTransfer });
}
Aggregations