Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 75931 Details for
Bug 160572
[new eux] add ability to attach images to tasks
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
crop same window
160572-crop-same.txt (text/plain), 14.44 KB, created by
Balazs Brinkus
on 2007-08-12 18:05:27 EDT
(
hide
)
Description:
crop same window
Filename:
MIME Type:
Creator:
Balazs Brinkus
Created:
2007-08-12 18:05:27 EDT
Size:
14.44 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.tasks.ui >Index: src/org/eclipse/mylyn/internal/tasks/ui/wizards/ScreenShotAttachmentPage.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/ScreenShotAttachmentPage.java,v >retrieving revision 1.1 >diff -u -r1.1 ScreenShotAttachmentPage.java >--- src/org/eclipse/mylyn/internal/tasks/ui/wizards/ScreenShotAttachmentPage.java 6 Jul 2007 18:50:44 -0000 1.1 >+++ src/org/eclipse/mylyn/internal/tasks/ui/wizards/ScreenShotAttachmentPage.java 12 Aug 2007 22:03:19 -0000 >@@ -12,18 +12,23 @@ > import org.eclipse.jface.wizard.IWizardPage; > import org.eclipse.jface.wizard.WizardPage; > import org.eclipse.mylyn.internal.tasks.core.LocalAttachment; >+import org.eclipse.mylyn.tasks.ui.TasksUiPlugin; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.ScrolledComposite; >+import org.eclipse.swt.events.ControlAdapter; >+import org.eclipse.swt.events.ControlEvent; >+import org.eclipse.swt.events.MouseEvent; >+import org.eclipse.swt.events.MouseListener; >+import org.eclipse.swt.events.MouseMoveListener; > import org.eclipse.swt.events.PaintEvent; > import org.eclipse.swt.events.PaintListener; > import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.events.SelectionListener; >+import org.eclipse.swt.graphics.Cursor; > import org.eclipse.swt.graphics.GC; > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; >-import org.eclipse.swt.layout.FillLayout; >-import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Canvas; >@@ -44,12 +49,20 @@ > > private Button makeShotButton; > >- private Button showShotButton; >+ private Button cropShotButton; >+ >+ private Button fitShotButton; > > private Image screenshotImage; > > private Canvas canvas; > >+ private ScrolledComposite scrolledComposite; >+ >+ private Rectangle cropRegionBounds; >+ >+ private boolean isCropFit; >+ > protected ScreenShotAttachmentPage(LocalAttachment attachment) { > super("ScreenShotAttachment"); > setTitle("Create a screenshot"); >@@ -58,64 +71,108 @@ > } > > public void createControl(Composite parent) { >+ > Composite composite = new Composite(parent, SWT.NONE); >- GridLayout gridLayout = new GridLayout(); >- gridLayout.numColumns = 2; >- composite.setLayout(gridLayout); >+ composite.setLayout(new GridLayout()); > setControl(composite); > >- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); >- composite.setLayout(new GridLayout(3, false)); >- >- makeShotButton = new Button(composite, SWT.PUSH); >- makeShotButton.setText("Take a screenshot"); >+ Composite buttonsComposite = new Composite(composite, SWT.NONE); >+ buttonsComposite.setLayout(new GridLayout(4, false)); >+ makeShotButton = new Button(buttonsComposite, SWT.PUSH); >+ makeShotButton.setText("Capture full screen"); >+ makeShotButton.setImage(TasksUiPlugin.imageDescriptorFromPlugin(TasksUiPlugin.ID_PLUGIN, >+ "icons/etool16/scr-fullscreen.gif").createImage()); > makeShotButton.addSelectionListener(new SelectionListener() { > > public void widgetSelected(SelectionEvent e) { > storeScreenshotContent(); > page.setErrorMessage(null); >- showShotButton.setEnabled(true); >+ cropShotButton.setEnabled(true); >+ fitShotButton.setEnabled(true); > } > > public void widgetDefaultSelected(SelectionEvent e) { >+ //ignore > } > > }); > >- showShotButton = new Button(composite, SWT.PUSH); >- showShotButton.setText("Show the screenshot"); >- showShotButton.addSelectionListener(new SelectionListener() { >+ cropShotButton = new Button(buttonsComposite, SWT.TOGGLE); >+ cropShotButton.setText("Crop a region"); >+ cropShotButton.setImage(TasksUiPlugin.imageDescriptorFromPlugin(TasksUiPlugin.ID_PLUGIN, >+ "icons/etool16/scr-crop.gif").createImage()); >+ cropShotButton.addSelectionListener(new SelectionListener() { > > public void widgetSelected(SelectionEvent e) { >- showScreenshotContent(); >+ drawCanvas(); >+ cropScreenshotContent(); > } > > public void widgetDefaultSelected(SelectionEvent e) { >+ //ignore > } > > }); >+ cropShotButton.setEnabled(false); >+ >+ fitShotButton = new Button(buttonsComposite, SWT.TOGGLE); >+ fitShotButton.setText("Fit image"); >+ fitShotButton.setImage(TasksUiPlugin.imageDescriptorFromPlugin(TasksUiPlugin.ID_PLUGIN, >+ "icons/etool16/scr-fit.gif").createImage()); >+ fitShotButton.addSelectionListener(new SelectionListener() { > >- canvas = new Canvas(composite, SWT.BORDER); >- canvas.setLayoutData(GridDataFactory.fillDefaults() >+ public void widgetSelected(SelectionEvent e) { >+ drawCanvas(); >+ } >+ >+ public void widgetDefaultSelected(SelectionEvent e) { >+ // ignore >+ } >+ >+ }); >+ fitShotButton.setSelection(true); >+ fitShotButton.setEnabled(false); >+ isCropFit = true; >+ >+ scrolledComposite = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); >+ scrolledComposite.setLayoutData(GridDataFactory.fillDefaults() > .align(SWT.FILL, SWT.FILL) > .grab(true, true) >- .span(2, 1) > .create()); > >+ canvas = new Canvas(scrolledComposite, SWT.DOUBLE_BUFFERED | SWT.NONE); >+ scrolledComposite.setContent(canvas); > canvas.addPaintListener(new PaintListener() { > public void paintControl(PaintEvent e) { > if (screenshotImage != null) { >- Rectangle screenBounds = screenshotImage.getBounds(); >+ Rectangle imageBounds = screenshotImage.getBounds(); > Rectangle canvasBounds = canvas.getBounds(); >- e.gc.drawImage(screenshotImage, 0, 0, screenBounds.width, screenBounds.height, 0, 0, >- canvasBounds.width, canvasBounds.height); >+ >+ if (fitShotButton.getSelection()) { >+ e.gc.drawImage(screenshotImage, 0, 0, imageBounds.width, imageBounds.height, 0, 0, >+ canvasBounds.width, canvasBounds.height); >+ } else >+ e.gc.drawImage(screenshotImage, 0, 0); >+ >+ if (cropRegionBounds != null && !cropShotButton.getSelection()) { >+ drawRegion(e.gc); >+ } >+ > } else { > page.setErrorMessage("Screenshot required"); >- showShotButton.setEnabled(false); >+ cropShotButton.setEnabled(false); >+ fitShotButton.setEnabled(false); > } > } > }); > >+ scrolledComposite.addControlListener(new ControlAdapter() { >+ @Override >+ public void controlResized(ControlEvent e) { >+ drawCanvas(); >+ } >+ }); >+ > } > > @Override >@@ -131,6 +188,7 @@ > attachment.setContentType("image/jpeg"); > page.setFilePath(InputAttachmentSourcePage.SCREENSHOT_LABEL); > page.setContentType(); >+ getCropScreenshot(); > return page; > } > >@@ -144,14 +202,17 @@ > final Display display = Display.getDefault(); > final Shell wizardShell = getWizard().getContainer().getShell(); > wizardShell.setVisible(false); >+ isCropFit = fitShotButton.getSelection(); > > display.asyncExec(new Runnable() { > public void run() { > GC gc = new GC(display); >- screenshotImage = new Image(display, display.getBounds()); >+ Rectangle displayBounds = display.getBounds(); >+ screenshotImage = new Image(display, displayBounds); > gc.copyArea(screenshotImage, 0, 0); >+ gc.drawRectangle(0, 0, displayBounds.width - 1, displayBounds.height - 1); > gc.dispose(); >- canvas.redraw(); >+ drawCanvas(); > wizardShell.setVisible(true); > if (screenshotImage != null) > setPageComplete(true); >@@ -159,38 +220,180 @@ > }); > } > >- private void showScreenshotContent() { >- Display display = Display.getDefault(); >+ private void cropScreenshotContent() { > >- Shell popup = new Shell(display.getActiveShell(), SWT.SHELL_TRIM); >- popup.setLayout(new FillLayout()); >- popup.setText("Screenshot Image"); >+ final Point downPoint = new Point(-1, -1); > >- Rectangle displayBounds = Display.getDefault().getBounds(); >- Point dialogSize = new Point(0, 0); >- dialogSize.x = displayBounds.width / 2; >- dialogSize.y = displayBounds.height / 2; >- Point dialoglocation = new Point(0, 0); >- dialoglocation.x = displayBounds.x + displayBounds.width / 2 - dialogSize.x / 2; >- dialoglocation.y = displayBounds.y + displayBounds.height / 2 - dialogSize.y / 2; >- popup.setSize(dialogSize); >- popup.setLocation(dialoglocation); >- >- ScrolledComposite sc = new ScrolledComposite(popup, SWT.V_SCROLL | SWT.H_SCROLL); >- Canvas canvas = new Canvas(sc, SWT.NONE); >- sc.setContent(canvas); >- canvas.setBounds(display.getBounds()); >- canvas.addPaintListener(new PaintListener() { >- public void paintControl(PaintEvent e) { >- if (screenshotImage != null) >- e.gc.drawImage(screenshotImage, 0, 0); >+ final Display display = Display.getDefault(); >+ >+ final Rectangle originalBounds = screenshotImage.getBounds(); >+ >+ final GC cropRegionGC = new GC(canvas); >+ >+ final MouseMoveListener mouseMoveListener = new MouseMoveListener() { >+ public void mouseMove(MouseEvent e) { >+ if (downPoint.x != -1 && downPoint.y != -1) { >+ int width = e.x - downPoint.x; >+ int height = e.y - downPoint.y; >+ canvas.redraw(); >+ cropRegionGC.drawRectangle(downPoint.x, downPoint.y, width, height); >+ } > } >- }); >- popup.open(); >+ }; >+ >+ final MouseListener mouseListener = new MouseListener() { >+ public void mouseUp(MouseEvent e) { >+ if (downPoint.x != -1 && downPoint.y != -1) { >+ >+ int width; >+ if (e.x > originalBounds.width) { >+ width = originalBounds.width - downPoint.x; >+ } else if (e.x < 0) { >+ width = downPoint.x; >+ downPoint.x = 0; >+ } else { >+ width = e.x - downPoint.x; >+ } >+ >+ int height; >+ if (e.y > originalBounds.height) { >+ height = originalBounds.height - downPoint.y; >+ } else if (e.y < 0) { >+ height = downPoint.y; >+ downPoint.y = 0; >+ } else { >+ height = e.y - downPoint.y; >+ } >+ >+ display.getActiveShell().setCursor(new Cursor(null, SWT.CURSOR_ARROW)); >+ >+ cropRegionBounds = new Rectangle(downPoint.x, downPoint.y, width, height); >+ drawRegion(cropRegionGC); >+ >+ canvas.removeMouseMoveListener(mouseMoveListener); >+ canvas.removeMouseListener(this); >+ downPoint.x = -1; >+ downPoint.y = -1; >+ >+ cropShotButton.setSelection(false); >+ } >+ } >+ >+ public void mouseDown(MouseEvent e) { >+ if (downPoint.x == -1 && downPoint.y == -1) { >+ display.getActiveShell().setCursor(new Cursor(null, SWT.CURSOR_CROSS)); >+ downPoint.x = e.x; >+ downPoint.y = e.y; >+ canvas.addMouseMoveListener(mouseMoveListener); >+ } >+ } >+ >+ public void mouseDoubleClick(MouseEvent e) { >+ // ignore >+ } >+ }; >+ >+ isCropFit = fitShotButton.getSelection(); >+ >+ canvas.addMouseListener(mouseListener); >+ >+ } >+ >+ private void drawCanvas() { >+ if (fitShotButton.getSelection()) { >+ Rectangle bounds = scrolledComposite.getBounds(); >+ bounds.x = 0; >+ bounds.y = 0; >+ bounds.width -= 5; >+ bounds.height -= 5; >+ canvas.setBounds(bounds); >+ } else { >+ canvas.setBounds(screenshotImage.getBounds()); >+ } >+ scrolledComposite.redraw(); >+ canvas.redraw(); >+ } >+ >+ private void drawRegion(GC gc) { >+ >+ Rectangle displayBounds = Display.getDefault().getBounds(); >+ Rectangle bounds = scrolledComposite.getBounds(); >+ bounds.width -= 5; >+ bounds.height -= 5; >+ >+ double ratioX = (double) displayBounds.width / (double) bounds.width; >+ double ratioY = (double) displayBounds.height / (double) bounds.height; >+ >+ Rectangle newCropRegion = new Rectangle(0, 0, 0, 0); >+ >+ if (isCropFit && !fitShotButton.getSelection()) { >+ newCropRegion.x = (int) (cropRegionBounds.x * ratioX); >+ newCropRegion.width = (int) (cropRegionBounds.width * ratioX); >+ newCropRegion.y = (int) (cropRegionBounds.y * ratioY); >+ newCropRegion.height = (int) (cropRegionBounds.height * ratioY); >+ } else if (!isCropFit && fitShotButton.getSelection()) { >+ newCropRegion.x = (int) (cropRegionBounds.x / ratioX); >+ newCropRegion.width = (int) (cropRegionBounds.width / ratioX); >+ newCropRegion.y = (int) (cropRegionBounds.y / ratioY); >+ newCropRegion.height = (int) (cropRegionBounds.height / ratioY); >+ } else { >+ newCropRegion = cropRegionBounds; >+ } >+ >+ Rectangle topRegionBounds = new Rectangle(0, 0, displayBounds.width, newCropRegion.y); >+ int bottomRegionY = newCropRegion.y + newCropRegion.height; >+ int bottomRegionHeight = displayBounds.height - bottomRegionY; >+ Rectangle bottomRegionBounds = new Rectangle(0, bottomRegionY, displayBounds.width, bottomRegionHeight); >+ Rectangle leftRegionBounds = new Rectangle(0, newCropRegion.y, newCropRegion.x, newCropRegion.height); >+ int rightRegionX = newCropRegion.x + newCropRegion.width; >+ int rightRegionWidth = displayBounds.width - rightRegionX; >+ Rectangle rightRegionBounds = new Rectangle(rightRegionX, newCropRegion.y, rightRegionWidth, >+ newCropRegion.height); >+ >+ gc.setLineStyle(SWT.LINE_DASH); >+ gc.setAdvanced(true); >+ gc.setAlpha(200); >+ >+ gc.fillRectangle(topRegionBounds); >+ gc.fillRectangle(bottomRegionBounds); >+ gc.fillRectangle(leftRegionBounds); >+ gc.fillRectangle(rightRegionBounds); >+ >+ gc.drawRectangle(newCropRegion); >+ } >+ >+ private Image getCropScreenshot() { >+ >+ if (cropRegionBounds == null) >+ return screenshotImage; >+ >+ Rectangle bounds; >+ if (!isCropFit) { >+ bounds = cropRegionBounds; >+ } else { >+ bounds = new Rectangle(0, 0, 0, 0); >+ Rectangle displayBounds = Display.getDefault().getBounds(); >+ Rectangle scrolledBounds = scrolledComposite.getBounds(); >+ double ratioX = (double) displayBounds.width / (double) scrolledBounds.width; >+ double ratioY = (double) displayBounds.height / (double) scrolledBounds.height; >+ bounds.x = (int) (cropRegionBounds.x * ratioX); >+ bounds.width = (int) (cropRegionBounds.width * ratioX); >+ bounds.y = (int) (cropRegionBounds.y * ratioY); >+ bounds.height = (int) (cropRegionBounds.height * ratioY); >+ } >+ >+ Image image = new Image(Display.getDefault(), bounds); >+ GC gc = new GC(image); >+ gc.drawImage(screenshotImage, bounds.x, bounds.y, bounds.width, bounds.height, 0, 0, bounds.width, >+ bounds.height); >+ gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1); >+ gc.dispose(); >+ >+ return image; > } > > public Image getScreenshotImage() { >- return screenshotImage; >+ return getCropScreenshot(); > } > > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 160572
:
72353
|
72354
|
72683
|
74874
|
75088
|
75089
|
75449
|
75450
|
75466
|
75467
| 75931 |
76061
|
76356
|
76357
|
77091