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 135048 Details for
Bug 266123
improve the capture method and the draw tool
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]
capture.patch
capture.patch (text/plain), 91.56 KB, created by
Hiroyuki
on 2009-05-09 04:29:44 EDT
(
hide
)
Description:
capture.patch
Filename:
MIME Type:
Creator:
Hiroyuki
Created:
2009-05-09 04:29:44 EDT
Size:
91.56 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.commons.ui >Index: src/org/eclipse/mylyn/internal/provisional/commons/ui/ScreenshotCreationPage.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/ScreenshotCreationPage.java,v >retrieving revision 1.9 >diff -u -r1.9 ScreenshotCreationPage.java >--- src/org/eclipse/mylyn/internal/provisional/commons/ui/ScreenshotCreationPage.java 14 Apr 2009 01:27:36 -0000 1.9 >+++ src/org/eclipse/mylyn/internal/provisional/commons/ui/ScreenshotCreationPage.java 9 May 2009 08:25:43 -0000 >@@ -9,6 +9,7 @@ > * Balazs Brinkus - initial API and implementation > * Tasktop Technologies - improvements > * Willian Mitsuda - improvements >+ * Hiroyuki Inaba - improvements > *******************************************************************************/ > > package org.eclipse.mylyn.internal.provisional.commons.ui; >@@ -16,6 +17,7 @@ > import java.util.ArrayList; > import java.util.EnumSet; > import java.util.HashMap; >+import java.util.HashSet; > import java.util.List; > import java.util.Map; > import java.util.Set; >@@ -32,13 +34,14 @@ > import org.eclipse.jface.layout.GridDataFactory; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.wizard.WizardPage; >-import org.eclipse.mylyn.internal.commons.ui.ColorSelectionWindow; > import org.eclipse.mylyn.internal.commons.ui.Messages; > import org.eclipse.swt.SWT; > import org.eclipse.swt.custom.ScrolledComposite; > import org.eclipse.swt.custom.ViewForm; > import org.eclipse.swt.events.ControlAdapter; > import org.eclipse.swt.events.ControlEvent; >+import org.eclipse.swt.events.MenuDetectEvent; >+import org.eclipse.swt.events.MenuDetectListener; > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.events.MouseMoveListener; >@@ -46,18 +49,26 @@ > import org.eclipse.swt.events.PaintListener; > import org.eclipse.swt.graphics.Color; > import org.eclipse.swt.graphics.Cursor; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.FontData; > import org.eclipse.swt.graphics.GC; > import org.eclipse.swt.graphics.Image; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.RGB; > import org.eclipse.swt.graphics.Rectangle; > import org.eclipse.swt.graphics.Region; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.layout.RowLayout; > import org.eclipse.swt.widgets.Canvas; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Display; > import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.MenuItem; > import org.eclipse.swt.widgets.Shell; >-import org.eclipse.swt.widgets.ToolItem; >+import org.eclipse.swt.widgets.Text; > import org.eclipse.ui.progress.UIJob; > > /** >@@ -71,21 +82,35 @@ > */ > public class ScreenshotCreationPage extends WizardPage { > >- private IAction captureAction; >+ private SelectToolAction captureAction; > >- private IAction fitAction; >+ private SelectToolAction fitAction; > > private IAction cropAction; > > private IAction markAction; > >- private IAction colorAction; >+ private IAction clearAction; > >- private Image colorIcon; >+ private IAction undoAction; > >- private Color markColor; >+ private IAction redoAction; > >- private IAction clearAction; >+ private Composite paletteArea; >+ >+ private SelectToolAction drawLineToolbar; >+ >+ private SelectToolAction drawArrowToolbar; >+ >+ private SelectToolAction drawBoxToolbar; >+ >+ private SelectToolAction drawTextToolbar; >+ >+ private SelectToolAction lineTypeToolbar; >+ >+ private SelectToolAction lineBoldToolbar; >+ >+ private SelectToolAction drawColorToolbar; > > private boolean imageDirty; > >@@ -99,6 +124,8 @@ > */ > private Image workImage; > >+ private Image previousImage; >+ > /** > * Used to draw into {@link #workImage} > */ >@@ -155,6 +182,26 @@ > */ > private EditorAction currentAction = EditorAction.CROPPING; > >+ private boolean isFirstCapture = true; >+ >+ private Text textArea; >+ >+ /** >+ * Mouse event history. Entry is [0] MouseDown/MouseMove/MouseUp, [1] x, [2] y >+ */ >+ private List<int[]> historyMouseEvent = new ArrayList<int[]>(); >+ >+ /** >+ * Draw tool history. Entry is [0] drawHistory index, [1] FREE/LINE/BOX/OVAL, [2] Line type, [3] Bold, [4] R/G/B >+ */ >+ private List<int[]> historyDrawTool = new ArrayList<int[]>(); >+ >+ private List<StringBuffer> historyDrawText = new ArrayList<StringBuffer>(); >+ >+ private List<String> historyDrawFont = new ArrayList<String>(); >+ >+ private int historyCheckpoint = 0; >+ > public ScreenshotCreationPage() { > super("ScreenShotAttachment"); //$NON-NLS-1$ > setTitle(Messages.ScreenshotCreationPage_CAPTURE_SCRRENSHOT); >@@ -173,13 +220,21 @@ > > // TODO: need disabled versions of all toolbar icons > ToolBarManager tbm = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT); >- captureAction = new Action(Messages.ScreenshotCreationPage_Capture_Desktop_C, IAction.AS_PUSH_BUTTON) { > >- private boolean isFirstCapture = true; >+ captureAction = new SelectToolAction(getShell(), Messages.ScreenshotCreationPage_Capture_Desktop_C, >+ SelectToolAction.CAPTURE_DROP_DOWN_MENU) { > > @Override > public void run() { >- captureScreenshotContent(); >+ if (captureAction.getSelect() == SelectToolAction.CAPTURE_DESKTOP) { >+ captureScreenshotContent(); >+ } else if (captureAction.getSelect() == SelectToolAction.CAPTURE_CLIPBOARD) { >+ captureScreenshotContent(captureAction.getClipboardImage()); >+ } else if (captureAction.getSelect() == SelectToolAction.CAPTURE_RECTANGLE) { >+ captureScreenshotContentFromSelection(); >+ } else { >+ captureScreenshotContent(captureAction.getFileImage()); >+ } > setErrorMessage(null); > if (isFirstCapture) { > isFirstCapture = false; >@@ -189,11 +244,24 @@ > markAction.setEnabled(true); > clearAction.setEnabled(false); > } >+ >+ historyMouseEvent = new ArrayList<int[]>(); >+ historyDrawTool = new ArrayList<int[]>(); >+ historyDrawText = new ArrayList<StringBuffer>(); >+ historyDrawFont = new ArrayList<String>(); >+ historyCheckpoint = 0; >+ undoAction.setEnabled(false); >+ redoAction.setEnabled(false); > } > >+ @Override >+ protected boolean isEnableRectangle() { >+ return (currentSelection != null); >+ } > }; > captureAction.setToolTipText(Messages.ScreenshotCreationPage_Capture_Desktop); > captureAction.setImageDescriptor(ImageDescriptor.createFromImage(CommonImages.getImage(CommonImages.IMAGE_CAPTURE))); >+ captureAction.setShowMenuAlways(false); > > // captureDelayedButton = new Button(buttonsComposite, SWT.PUSH); > // final String captureIn = "Capture in "; >@@ -228,16 +296,16 @@ > // } > // }); > >- fitAction = new Action("", IAction.AS_CHECK_BOX) { //$NON-NLS-1$ >+ fitAction = new SelectToolAction(Messages.ScreenshotCreationPage_Fit_Image_F, >+ SelectToolAction.ZOOM_DROP_DOWN_MENU) { > @Override > public void run() { > refreshCanvasSize(); > } > }; > fitAction.setToolTipText(Messages.ScreenshotCreationPage_Fit_Image); >- fitAction.setText(Messages.ScreenshotCreationPage_Fit_Image_F); > fitAction.setImageDescriptor(ImageDescriptor.createFromImage(CommonImages.getImage(CommonImages.IMAGE_FIT))); >- fitAction.setChecked(true); >+ //fitAction.setChecked(true); > fitAction.setEnabled(false); > > cropAction = new Action(Messages.ScreenshotCreationPage_Crop_R, IAction.AS_RADIO_BUTTON) { >@@ -246,7 +314,8 @@ > currentAction = EditorAction.CROPPING; > cropAction.setChecked(true); > markAction.setChecked(false); >- colorAction.setEnabled(false); >+ undoAction.setEnabled(false); >+ redoAction.setEnabled(false); > canvas.redraw(); > } > }; >@@ -256,11 +325,27 @@ > > markAction = new Action(Messages.ScreenshotCreationPage_Annotate, IAction.AS_RADIO_BUTTON) { > @Override >+ public void setChecked(boolean checked) { >+ super.setChecked(checked); >+ if (paletteArea != null) { >+ boolean isDrawText = (drawTextToolbar.getSelect() >= 0) ? false : checked; >+ drawLineToolbar.setEnabled(checked); >+ drawArrowToolbar.setEnabled(checked); >+ drawBoxToolbar.setEnabled(checked); >+ drawTextToolbar.setEnabled(checked); >+ drawColorToolbar.setEnabled(isDrawText); >+ lineTypeToolbar.setEnabled(isDrawText); >+ lineBoldToolbar.setEnabled(isDrawText); >+ } >+ } >+ >+ @Override > public void run() { > currentAction = EditorAction.MARKING; > cropAction.setChecked(false); > markAction.setChecked(true); >- colorAction.setEnabled(true); >+ undoAction.setEnabled(false); >+ redoAction.setEnabled(false); > canvas.redraw(); > } > }; >@@ -269,58 +354,87 @@ > // markAction.setDisabledImageDescriptor(ImageDescriptor.createFromFile(getClass(), "mark_disabled.gif")); > markAction.setEnabled(false); > >- colorAction = new Action("", IAction.AS_DROP_DOWN_MENU) { //$NON-NLS-1$ >- @Override >- public void runWithEvent(final Event e) { >- final ColorSelectionWindow colorWindow = new ColorSelectionWindow(getControl().getShell()) { >- >- @Override >- protected Point getInitialLocation(Point initialSize) { >- ToolItem toolItem = (ToolItem) e.widget; >- Rectangle itemBounds = toolItem.getBounds(); >- Point location = toolItem.getParent().toDisplay(itemBounds.x + itemBounds.width, >- itemBounds.y + itemBounds.height); >- location.x -= initialSize.x; >- return location; >- } >- >- }; >- colorWindow.setBlockOnOpen(true); >- colorWindow.open(); >- RGB color = colorWindow.getSelectedRGB(); >- if (color != null) { >- setMarkColor(color); >- } >- } >- }; >- colorAction.setToolTipText(Messages.ScreenshotCreationPage_Change_pen_color); >- colorIcon = new Image(getShell().getDisplay(), 16, 16); >- setMarkColor(new RGB(255, 85, 85)); >- colorAction.setEnabled(false); >- >- clearAction = new Action(Messages.ScreenshotCreationPage_Clear_Annotations, IAction.AS_PUSH_BUTTON) { >+ clearAction = new Action(Messages.ScreenshotCreationPage_Clear, IAction.AS_PUSH_BUTTON) { > @Override > public void run() { > clearAction.setEnabled(false); > workImageGC.drawImage(originalImage, 0, 0); > canvas.redraw(); > setImageDirty(true); >+ >+ historyMouseEvent = new ArrayList<int[]>(); >+ historyDrawTool = new ArrayList<int[]>(); >+ historyDrawText = new ArrayList<StringBuffer>(); >+ historyDrawFont = new ArrayList<String>(); >+ historyCheckpoint = 0; >+ undoAction.setEnabled(false); >+ redoAction.setEnabled(false); > } > }; > clearAction.setToolTipText(Messages.ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image); > clearAction.setImageDescriptor(CommonImages.CLEAR); > clearAction.setEnabled(false); > >+ undoAction = new Action(Messages.ScreenshotCreationPage_Undo) { >+ @Override >+ public void run() { >+ if (historyCheckpoint > 0) { >+ historyCheckpoint--; >+ drawAnnotationHistory(); >+ } >+ if (historyCheckpoint == 0) { >+ undoAction.setEnabled(false); >+ } >+ if (historyCheckpoint < historyDrawTool.size()) { >+ redoAction.setEnabled(true); >+ } >+ } >+ }; >+ undoAction.setToolTipText(Messages.ScreenshotCreationPage_Undo_annotation); >+ undoAction.setImageDescriptor(CommonImages.EDIT_UNDO); >+ undoAction.setEnabled(false); >+ >+ redoAction = new Action(Messages.ScreenshotCreationPage_Redo) { >+ @Override >+ public void run() { >+ if (historyCheckpoint < historyDrawTool.size()) { >+ historyCheckpoint++; >+ drawAnnotationHistory(); >+ } >+ if (historyCheckpoint > 0) { >+ undoAction.setEnabled(true); >+ } >+ if (historyCheckpoint >= historyDrawTool.size()) { >+ redoAction.setEnabled(false); >+ } >+ } >+ }; >+ redoAction.setToolTipText(Messages.ScreenshotCreationPage_Redo_annotation); >+ redoAction.setImageDescriptor(CommonImages.EDIT_REDO); >+ redoAction.setEnabled(false); >+ > tbm.add(createAndConfigureCI(captureAction)); >- tbm.add(createAndConfigureCI(fitAction)); > tbm.add(new Separator()); >+ tbm.add(createAndConfigureCI(fitAction)); > tbm.add(createAndConfigureCI(cropAction)); > tbm.add(createAndConfigureCI(markAction)); >- tbm.add(createAndConfigureCI(colorAction)); > tbm.add(new Separator()); > tbm.add(createAndConfigureCI(clearAction)); >+ tbm.add(createAndConfigureCI(undoAction)); >+ tbm.add(createAndConfigureCI(redoAction)); >+ tbm.add(new Separator()); >+ >+ Composite body = new Composite(vf, SWT.NONE); >+ GridLayout layout = new GridLayout(2, false); >+ layout.horizontalSpacing = 0; >+ layout.verticalSpacing = 0; >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ body.setLayout(layout); >+ createPaletteBars(body); > >- scrolledComposite = new ScrolledComposite(vf, SWT.V_SCROLL | SWT.H_SCROLL); >+ scrolledComposite = new ScrolledComposite(body, SWT.V_SCROLL | SWT.H_SCROLL); >+ scrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); > canvas = new Canvas(scrolledComposite, SWT.DOUBLE_BUFFERED); > scrolledComposite.setContent(canvas); > canvas.addPaintListener(new PaintListener() { >@@ -330,11 +444,23 @@ > Rectangle imageBounds = workImage.getBounds(); > Rectangle canvasBounds = canvas.getClientArea(); > >- if (fitAction.isChecked()) { >- e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, 0, 0, >- canvasBounds.width, canvasBounds.height); >- } else { >+ int zoom = fitAction.getSelect(); >+ switch (zoom) { >+ case SelectToolAction.ZOOM_FIT: >+ e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, // >+ 0, 0, canvasBounds.width, canvasBounds.height); >+ break; >+ case 50: >+ e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, // >+ 0, 0, imageBounds.width / 2, imageBounds.height / 2); >+ break; >+ case 100: > e.gc.drawImage(workImage, 0, 0); >+ break; >+ default: >+ e.gc.drawImage(workImage, 0, 0, imageBounds.width, imageBounds.height, // >+ 0, 0, imageBounds.width * zoom / 100, imageBounds.height * zoom / 100); >+ break; > } > drawSelection(e.gc); > } else { >@@ -347,7 +473,7 @@ > scrolledComposite.addControlListener(new ControlAdapter() { > @Override > public void controlResized(ControlEvent e) { >- if (fitAction.isChecked()) { >+ if (fitAction.getSelect() == SelectToolAction.ZOOM_FIT) { > refreshCanvasSize(); > } > } >@@ -355,45 +481,139 @@ > scrolledComposite.setEnabled(false); > > vf.setTopLeft(tbm.createControl(vf)); >- vf.setContent(scrolledComposite); >+ vf.setContent(body); > registerMouseListeners(); > >+ vf.setLayoutData(new GridData(GridData.FILL_BOTH)); >+ > Dialog.applyDialogFont(vf); > } > >- private ActionContributionItem createAndConfigureCI(IAction action) { >- ActionContributionItem ci = new ActionContributionItem(action); >- ci.setMode(ActionContributionItem.MODE_FORCE_TEXT); >- return ci; >- } >+ private void createPaletteBars(Composite body) { >+ paletteArea = new Composite(body, SWT.NONE); >+ paletteArea.setLayoutData(new GridData(GridData.FILL_VERTICAL)); >+ RowLayout rowlayout = new RowLayout(SWT.VERTICAL); >+ rowlayout.marginRight += 1; >+ paletteArea.setLayout(rowlayout); >+ >+ paletteArea.addListener(SWT.Paint, new Listener() { >+ public void handleEvent(Event e) { >+ Color gcForeground = e.gc.getForeground(); >+ Rectangle bounds = ((Composite) e.widget).getBounds(); >+ Color border = e.widget.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); >+ e.gc.setForeground(border); >+ e.gc.drawLine(bounds.width - 1, 0, bounds.width - 1, bounds.height); >+ e.gc.setForeground(gcForeground); >+ } >+ }); >+ paletteArea.addMenuDetectListener(new MenuDetectListener() { >+ >+ public void menuDetected(MenuDetectEvent e) { >+ Menu rightClickMenu = new Menu(Display.getDefault().getActiveShell(), SWT.POP_UP); >+ MenuItem menuItem = new MenuItem(rightClickMenu, SWT.CHECK); >+ menuItem.setText(Messages.ScreenshotCreationPage_Show_Line_Type_Selector); >+ menuItem.setSelection(lineTypeToolbar.getVisible()); >+ menuItem.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(final Event event) { >+ lineTypeToolbar.setVisible(!lineTypeToolbar.getVisible()); >+ paletteArea.layout(); >+ } >+ }); >+ menuItem = new MenuItem(rightClickMenu, SWT.CHECK); >+ menuItem.setText(Messages.ScreenshotCreationPage_Show_Line_Bold_Selector); >+ menuItem.setSelection(lineBoldToolbar.getVisible()); >+ menuItem.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(final Event event) { >+ lineBoldToolbar.setVisible(!lineBoldToolbar.getVisible()); >+ paletteArea.layout(); >+ } >+ }); >+ rightClickMenu.setLocation(e.x, e.y); >+ rightClickMenu.setVisible(true); >+ } >+ }); >+ drawLineToolbar = new SelectToolAction(paletteArea, SelectToolAction.DRAWLINE_TOOLBAR) { >+ >+ @Override >+ public void run() { >+ drawArrowToolbar.setUnselect(); >+ drawBoxToolbar.setUnselect(); >+ drawTextToolbar.setUnselect(); >+ } >+ }; >+ drawLineToolbar.setEnabled(false); >+ drawArrowToolbar = new SelectToolAction(paletteArea, SelectToolAction.DRAWARROW_TOOLBAR) { > >- private void setMarkColor(RGB color) { >- if (markColor != null) { >- markColor.dispose(); >+ @Override >+ public void run() { >+ drawLineToolbar.setUnselect(); >+ drawBoxToolbar.setUnselect(); >+ drawTextToolbar.setUnselect(); >+ drawColorToolbar.setEnabled(true); >+ lineTypeToolbar.setEnabled(true); >+ lineBoldToolbar.setEnabled(true); >+ } >+ }; >+ drawArrowToolbar.setEnabled(false); >+ drawBoxToolbar = new SelectToolAction(paletteArea, SelectToolAction.DRAWBOX_TOOLBAR) { >+ >+ @Override >+ public void run() { >+ drawLineToolbar.setUnselect(); >+ drawArrowToolbar.setUnselect(); >+ drawTextToolbar.setUnselect(); >+ drawColorToolbar.setEnabled(true); >+ lineTypeToolbar.setEnabled(true); >+ lineBoldToolbar.setEnabled(true); >+ } >+ }; >+ drawBoxToolbar.setEnabled(false); >+ drawTextToolbar = new SelectToolAction(paletteArea, SelectToolAction.DRAWTEXT_TOOLBAR) { >+ >+ @Override >+ public void run() { >+ drawLineToolbar.setUnselect(); >+ drawArrowToolbar.setUnselect(); >+ drawBoxToolbar.setUnselect(); >+ drawColorToolbar.setEnabled(false); >+ lineTypeToolbar.setEnabled(false); >+ lineBoldToolbar.setEnabled(false); >+ } >+ }; >+ drawTextToolbar.setEnabled(false); >+ drawColorToolbar = new SelectToolAction(paletteArea, SelectToolAction.COLOR_TOOLBAR); >+ drawColorToolbar.setEnabled(false); >+ lineTypeToolbar = new SelectToolAction(paletteArea, SelectToolAction.LINETYPE_TOOLBAR); >+ lineTypeToolbar.setEnabled(false); >+ lineTypeToolbar.setVisible(false); >+ lineBoldToolbar = new SelectToolAction(paletteArea, SelectToolAction.LINEBOLD_TOOLBAR); >+ lineBoldToolbar.setEnabled(false); >+ lineBoldToolbar.setVisible(false); >+ } >+ >+ private int getSelectDrawToolbar() { >+ int drawTool; >+ if ((drawTool = drawLineToolbar.getSelect()) >= 0) { >+ return drawTool; > } >- markColor = new Color(getShell().getDisplay(), color); >- if (workImageGC != null) { >- workImageGC.setForeground(markColor); >+ if ((drawTool = drawArrowToolbar.getSelect()) >= 0) { >+ return drawTool; > } >+ if ((drawTool = drawBoxToolbar.getSelect()) >= 0) { >+ return drawTool; >+ } >+ return SelectToolAction.DRAW_TEXT; >+ } > >- GC colorGC = new GC(colorIcon); >- colorGC.setBackground(markColor); >- colorGC.fillRectangle(0, 0, 16, 16); >- colorGC.drawRectangle(0, 0, 15, 15); >- colorGC.dispose(); >- >- colorAction.setImageDescriptor(ImageDescriptor.createFromImage(colorIcon)); >+ private ActionContributionItem createAndConfigureCI(IAction action) { >+ ActionContributionItem ci = new ActionContributionItem(action); >+ ci.setMode(ActionContributionItem.MODE_FORCE_TEXT); >+ return ci; > } > > @Override > public void dispose() { > disposeImageResources(); >- if (markColor != null) { >- markColor.dispose(); >- } >- if (colorIcon != null) { >- colorIcon.dispose(); >- } > > canvas.setCursor(null); > for (Cursor cursor : cursors.values()) { >@@ -440,11 +660,74 @@ > int y = (int) Math.round(currentSelection.y * scaleFactor); > int right = (int) Math.round((currentSelection.x + currentSelection.width) * scaleFactor); > int bottom = (int) Math.round((currentSelection.y + currentSelection.height) * scaleFactor); >- int width = Math.min(right, (int) Math.round((workImage.getBounds().width - 1) * scaleFactor)) - x; >- int height = Math.min(bottom, (int) Math.round((workImage.getBounds().height - 1) * scaleFactor)) - y; >+ int width = Math.min(right, (int) Math.round(workImage.getBounds().width * scaleFactor)) - x; >+ int height = Math.min(bottom, (int) Math.round(workImage.getBounds().height * scaleFactor)) - y; > return new Rectangle(x, y, width, height); > } > >+ private Rectangle getOutsideSelection(Rectangle rectangle) { >+ if (rectangle == null) { >+ return null; >+ } >+ return new Rectangle(rectangle.x - SQUARE_SIZE * 2, rectangle.y - SQUARE_SIZE * 2, // >+ rectangle.width + SQUARE_SIZE * 4 + 1, rectangle.height + SQUARE_SIZE * 4 + 1); >+ } >+ >+ private static final int[][] grapGroupPoints = { // >+ /* */{ 0, 0, 0 }, { 1, 0, 0 }, { 2, 0, 1 }, { 3, 0, 2 }, { 4, 0, 2 }, // >+ { 0, 1, 0 }, /* *//* *//* */{ 4, 1, 2 }, // >+ { 0, 2, 3 }, /* *//* *//* */{ 4, 2, 4 }, // >+ { 0, 3, 5 }, /* *//* *//* */{ 4, 3, 7 }, // >+ { 0, 4, 5 }, { 1, 4, 5 }, { 2, 4, 6 }, { 3, 4, 7 }, { 4, 4, 7 } }; >+ >+ private static final int[] grapScanOrder = { 0, 4, 1, 3, 2 }; >+ >+ private int getGrabPoint(int x, int y) { >+ if (currentSelection == null) { >+ return -1; >+ } >+ >+ Rectangle inside = getScaledSelection(); >+ Rectangle outside = getOutsideSelection(inside); >+ int[] xGroupPoint = { outside.x, // >+ inside.x, // >+ inside.x + SQUARE_SIZE * 4, // >+ inside.x + inside.width - SQUARE_SIZE * 4, // >+ inside.x + inside.width, // >+ outside.x + outside.width }; >+ int[] yGroupPoint = { outside.y, // >+ inside.y, // >+ inside.y + SQUARE_SIZE * 4, // >+ inside.y + inside.height - SQUARE_SIZE * 4, // >+ inside.y + inside.height, // >+ outside.y + outside.height }; >+ int xGroup = -1, yGroup = -1; >+ for (int element : grapScanOrder) { >+ if (xGroupPoint[element] <= x && x <= xGroupPoint[element + 1]) { >+ xGroup = element; >+ break; >+ } >+ } >+ if (xGroup < 0) { >+ return -1; >+ } >+ for (int element : grapScanOrder) { >+ if (yGroupPoint[element] <= y && y <= yGroupPoint[element + 1]) { >+ yGroup = element; >+ break; >+ } >+ } >+ if (yGroup < 0) { >+ return -1; >+ } >+ for (int[] element : grapGroupPoints) { >+ if (element[0] == xGroup && element[1] == yGroup) { >+ return element[2]; >+ } >+ } >+ return -1; >+ } >+ > @Override > public boolean isPageComplete() { > return workImage != null; >@@ -455,6 +738,53 @@ > return isPageComplete(); > } > >+ private void captureScreenshotContent(Image image) { >+ final Display display = getShell().getDisplay(); >+ disposeImageResources(); >+ originalImage = image; >+ Rectangle displayBounds = originalImage.getBounds(); >+ workImage = new Image(display, displayBounds.width, displayBounds.height); >+ GC gc = new GC(workImage); >+ gc.drawImage(originalImage, 0, 0); >+ gc.dispose(); >+ >+ workImageGC = new GC(workImage); >+ workImageGC.setLineCap(SWT.CAP_ROUND); >+ >+ scrolledComposite.setEnabled(true); >+ clearSelection(); >+ refreshCanvasSize(); >+ >+ setPageComplete(true); >+ } >+ >+ private void captureScreenshotContentFromSelection() { >+ Display display = getShell().getDisplay(); >+ >+ Image image = new Image(display, currentSelection); >+ GC gc = new GC(image); >+ gc.drawImage(workImage, currentSelection.x, currentSelection.y, currentSelection.width, >+ currentSelection.height, 0, 0, currentSelection.width, currentSelection.height); >+ gc.dispose(); >+ disposeImageResources(); >+ >+ originalImage = image; >+ Rectangle displayBounds = originalImage.getBounds(); >+ workImage = new Image(display, displayBounds.width, displayBounds.height); >+ gc = new GC(workImage); >+ gc.drawImage(originalImage, 0, 0); >+ gc.dispose(); >+ >+ workImageGC = new GC(workImage); >+ workImageGC.setLineCap(SWT.CAP_ROUND); >+ >+ scrolledComposite.setEnabled(true); >+ clearSelection(); >+ refreshCanvasSize(); >+ >+ setPageComplete(true); >+ } >+ > private void captureScreenshotContent() { > final Display display = getShell().getDisplay(); > final Shell wizardShell = getWizard().getContainer().getShell(); >@@ -476,8 +806,6 @@ > gc.dispose(); > > workImageGC = new GC(workImage); >- workImageGC.setForeground(markColor); >- workImageGC.setLineWidth(4); > workImageGC.setLineCap(SWT.CAP_ROUND); > > scrolledComposite.setEnabled(true); >@@ -514,34 +842,13 @@ > currentSelection.intersect(imageBounds); > } > >- /** >- * Create the grab points to resize the selection; this method should be called every time the selection or zoom >- * level is changed >- */ >- private void setUpGrabPoints() { >- grabPoints.clear(); >- if (currentSelection == null) { >- return; >- } >+ private static final int grabPointCurosr[] = { SWT.CURSOR_SIZENWSE, SWT.CURSOR_SIZENS, SWT.CURSOR_SIZENESW, >+ SWT.CURSOR_SIZEWE, SWT.CURSOR_SIZEWE, SWT.CURSOR_SIZENESW, SWT.CURSOR_SIZENS, SWT.CURSOR_SIZENWSE }; > >- Rectangle scaledSelection = getScaledSelection(); >- grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x, scaledSelection.y, SWT.CURSOR_SIZENWSE, EnumSet.of( >- SelectionSide.LEFT, SelectionSide.TOP))); >- grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width / 2, scaledSelection.y, >- SWT.CURSOR_SIZENS, EnumSet.of(SelectionSide.TOP))); >- grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width, scaledSelection.y, >- SWT.CURSOR_SIZENESW, EnumSet.of(SelectionSide.TOP, SelectionSide.RIGHT))); >- grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x, scaledSelection.y + scaledSelection.height / 2, >- SWT.CURSOR_SIZEWE, EnumSet.of(SelectionSide.LEFT))); >- grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width, scaledSelection.y >- + scaledSelection.height / 2, SWT.CURSOR_SIZEWE, EnumSet.of(SelectionSide.RIGHT))); >- grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x, scaledSelection.y + scaledSelection.height, >- SWT.CURSOR_SIZENESW, EnumSet.of(SelectionSide.LEFT, SelectionSide.BOTTOM))); >- grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width / 2, scaledSelection.y >- + scaledSelection.height, SWT.CURSOR_SIZENS, EnumSet.of(SelectionSide.BOTTOM))); >- grabPoints.add(GrabPoint.createGrabPoint(scaledSelection.x + scaledSelection.width, scaledSelection.y >- + scaledSelection.height, SWT.CURSOR_SIZENWSE, EnumSet.of(SelectionSide.BOTTOM, SelectionSide.RIGHT))); >- } >+ private static final SelectionSide[][] grabPointResizableSides = { { SelectionSide.LEFT, SelectionSide.TOP }, >+ { SelectionSide.TOP }, { SelectionSide.TOP, SelectionSide.RIGHT }, { SelectionSide.LEFT }, >+ { SelectionSide.RIGHT }, { SelectionSide.LEFT, SelectionSide.BOTTOM }, { SelectionSide.BOTTOM }, >+ { SelectionSide.BOTTOM, SelectionSide.RIGHT } }; > > private void refreshSelectionResize(int x, int y) { > currentSelection = new Rectangle(originalSelection.x, originalSelection.y, originalSelection.width, >@@ -559,7 +866,7 @@ > } > if (resizableSides.contains(SelectionSide.RIGHT)) { > deltaX = Math.max(deltaX, -originalSelection.width); >- if (originalSelection.x + originalSelection.width + deltaX - 1 > imageBounds.width) { >+ if (originalSelection.x + originalSelection.width + deltaX > imageBounds.width) { > deltaX = imageBounds.width - (originalSelection.x + originalSelection.width); > } > } >@@ -571,7 +878,7 @@ > } > if (resizableSides.contains(SelectionSide.BOTTOM)) { > deltaY = Math.max(deltaY, -originalSelection.height); >- if (originalSelection.y + originalSelection.height + deltaY - 1 > imageBounds.height) { >+ if (originalSelection.y + originalSelection.height + deltaY > imageBounds.height) { > deltaY = imageBounds.height - (originalSelection.y + originalSelection.height); > } > } >@@ -591,8 +898,6 @@ > if (resizableSides.contains(SelectionSide.BOTTOM)) { > currentSelection.height += deltaY; > } >- >- setUpGrabPoints(); > } > > private void refreshSelectionPosition(int x, int y) { >@@ -605,15 +910,13 @@ > newY = 0; > } > Rectangle imageBounds = workImage.getBounds(); >- if (newX + originalSelection.width - 1 > imageBounds.width) { >+ if (newX + originalSelection.width > imageBounds.width) { > newX = imageBounds.width - originalSelection.width; > } >- if (newY + originalSelection.height - 1 > imageBounds.height) { >+ if (newY + originalSelection.height > imageBounds.height) { > newY = imageBounds.height - originalSelection.height; > } > currentSelection = new Rectangle(newX, newY, originalSelection.width, originalSelection.height); >- >- setUpGrabPoints(); > } > > private void registerMouseListeners() { >@@ -639,12 +942,10 @@ > boolean cursorSet = false; > > // No selection in course, but have something selected; first test if I'm hovering some grab point >- for (GrabPoint point : grabPoints) { >- if (point.grabArea.contains(e.x, e.y)) { >- canvas.setCursor(cursors.get(point.cursorType)); >- cursorSet = true; >- break; >- } >+ int info = getGrabPoint(e.x, e.y); >+ if (info >= 0) { >+ canvas.setCursor(cursors.get(grabPointCurosr[info])); >+ cursorSet = true; > } > > // Test if I'm inside selection, so I can move it >@@ -659,6 +960,29 @@ > canvas.setCursor(crossCursor); > } > } else if (currentAction == EditorAction.MARKING) { >+ if (startPoint != null) { >+ int drawTool = getSelectDrawToolbar(); >+ if (drawTool == SelectToolAction.DRAW_FREE) { >+ int[] history = new int[3]; >+ history[0] = SWT.MouseMove; >+ history[1] = scaledX; >+ history[2] = scaledY; >+ historyMouseEvent.add(history); >+ } else { >+ int[] history = historyMouseEvent.get(historyMouseEvent.size() - 1); >+ if (history[0] == SWT.MouseMove) { >+ history[1] = scaledX; >+ history[2] = scaledY; >+ } else { >+ history = new int[3]; >+ history[0] = SWT.MouseMove; >+ history[1] = scaledX; >+ history[2] = scaledY; >+ historyMouseEvent.add(history); >+ } >+ } >+ } >+ > drawMarkLine(scaledX, scaledY); > > Cursor markCursor = cursors.get(CURSOR_MARK_TOOL); >@@ -667,7 +991,6 @@ > } > } > } >- > }); > > canvas.addMouseListener(new MouseAdapter() { >@@ -692,19 +1015,153 @@ > if (currentSelection.width == 0 && currentSelection.height == 0) { > currentSelection = null; > } >- setUpGrabPoints(); >+ > startPoint = null; > currentAction = EditorAction.CROPPING; > > canvas.redraw(); > setImageDirty(true); > } else if (currentAction == EditorAction.MARKING) { >+ if (startPoint != null) { >+ int drawTool = getSelectDrawToolbar(); >+ if (drawTool != SelectToolAction.DRAW_FREE) { >+ if (drawTool == SelectToolAction.DRAW_TEXT) { >+ drawAnnotationText(); >+ } >+ previousImage.dispose(); >+ previousImage = null; >+ } >+ >+ int[] history = new int[3]; >+ history[0] = SWT.MouseUp; >+ history[1] = 0; >+ history[2] = 0; >+ historyMouseEvent.add(history); >+ } >+ > startPoint = null; > setImageDirty(true); > } > } > > /** >+ * Input annotation text and draw text >+ */ >+ private void drawAnnotationText() { >+ workImageGC.drawImage(previousImage, 0, 0); >+ canvas.redraw(); >+ >+ int[] history = historyMouseEvent.get(historyMouseEvent.size() - 1); >+ if (history[0] != SWT.MouseMove) { >+ historyCheckpoint--; >+ updateAnnotationHistory(); >+ return; >+ } >+ >+ int endedPoint_x, endedPoint_y; >+ if (history[1] < startPoint.x) { >+ endedPoint_x = startPoint.x; >+ startPoint.x = history[1]; >+ } else { >+ endedPoint_x = history[1]; >+ } >+ if (history[2] < startPoint.y) { >+ endedPoint_y = startPoint.y; >+ startPoint.y = history[2]; >+ } else { >+ endedPoint_y = history[2]; >+ } >+ final Rectangle bounds = new Rectangle(startPoint.x, startPoint.y, endedPoint_x - startPoint.x, >+ endedPoint_y - startPoint.y); >+ textArea = new Text(canvas, SWT.MULTI | SWT.WRAP); >+ int xs = (int) Math.round(startPoint.x * scaleFactor); >+ int ys = (int) Math.round(startPoint.y * scaleFactor); >+ int xe = (int) Math.round(endedPoint_x * scaleFactor); >+ int ye = (int) Math.round(endedPoint_y * scaleFactor); >+ textArea.setBounds(new Rectangle(xs, ys, xe - xs, ye - ys)); >+ FontData fontData = new FontData(drawTextToolbar.getStringCustom()); >+ if (scaleFactor != 1.0) { >+ fontData.setHeight((int) Math.round(fontData.getHeight() * scaleFactor)); >+ } >+ textArea.setFont(new Font(getShell().getDisplay(), fontData)); >+ textArea.setForeground(new Color(getShell().getDisplay(), >+ SelectToolAction.int2rgb(drawTextToolbar.getIntgerCustom()))); >+ textArea.setTabs(1); >+ Point point = textArea.getCaretLocation(); >+ textArea.setBounds(new Rectangle(xs - point.x, ys, xe - xs + point.x + point.x, ye - ys)); >+ textArea.setFocus(); >+ textArea.addListener(SWT.Deactivate, new Listener() { >+ >+ public void handleEvent(Event event) { >+ String text = textArea.getText(); >+ { >+ String newtext = ""; //$NON-NLS-1$ >+ int currpos = 0; >+ int charpos = currpos; >+ textArea.setTopIndex(0); >+ textArea.setSelection(currpos); >+ int linepos = textArea.getCaretLineNumber(); >+ boolean remove1st = false; >+ String line; >+ while (currpos < text.length()) { >+ int y = textArea.getCaretLineNumber(); >+ if (linepos != y) { >+ line = text.substring(charpos, currpos); >+ if (line.endsWith("\n")) { //$NON-NLS-1$ >+ line = line.substring(0, line.length() - 1); >+ } >+ newtext = newtext + "\n" + line; //$NON-NLS-1$ >+ remove1st = true; >+ charpos = currpos; >+ linepos = y; >+ } >+ currpos++; >+ textArea.setSelection(currpos); >+ } >+ line = text.substring(charpos, currpos); >+ if (line.endsWith("\n")) { //$NON-NLS-1$ >+ line = line.substring(0, line.length() - 1); >+ } >+ if (line.length() > 0) { >+ newtext = newtext + "\n" + text.substring(charpos, currpos); //$NON-NLS-1$ >+ remove1st = true; >+ } >+ currpos = newtext.indexOf("\r"); //$NON-NLS-1$ >+ while (currpos > 0) { >+ newtext = newtext.substring(0, currpos) + newtext.substring(currpos + 1); >+ currpos = newtext.indexOf("\r"); //$NON-NLS-1$ >+ } >+ newtext = newtext.replace("\t", " "); //$NON-NLS-1$//$NON-NLS-2$ >+ if (remove1st) { >+ newtext = newtext.substring(1); >+ } >+ text = newtext; >+ } >+ >+ textArea.dispose(); >+ textArea = null; >+ >+ if (text.length() > 0) { >+ historyDrawText.get(historyCheckpoint - 1).append(text); >+ Color color = workImageGC.getForeground(); >+ FontData fontData = new FontData(drawTextToolbar.getStringCustom()); >+ workImageGC.setFont(new Font(getShell().getDisplay(), fontData)); >+ workImageGC.setForeground(new Color(getShell().getDisplay(), >+ SelectToolAction.int2rgb(drawTextToolbar.getIntgerCustom()))); >+ workImageGC.setClipping(bounds); >+ workImageGC.drawText(text, bounds.x, bounds.y, true); >+ workImageGC.setClipping((Rectangle) null); >+ workImageGC.setForeground(color); >+ } else { >+ historyCheckpoint--; >+ updateAnnotationHistory(); >+ } >+ canvas.redraw(); >+ } >+ }); >+ } >+ >+ /** > * Pressing mouse button starts a selection or a drawing; normalizes and marks the start point > */ > @Override >@@ -713,6 +1170,57 @@ > int scaledY = (int) (e.y / scaleFactor); > > if (currentAction == EditorAction.MARKING) { >+ updateAnnotationHistory(); >+ >+ int drawTool = getSelectDrawToolbar(); >+ int[] history = new int[5]; >+ history[0] = historyMouseEvent.size(); >+ history[1] = drawTool; >+ history[2] = (lineTypeToolbar != null) ? lineTypeToolbar.getSelect() : SWT.LINE_DOT; >+ history[3] = (lineBoldToolbar != null) ? lineBoldToolbar.getSelect() : 1; >+ RGB rgb; >+ if (drawTool == SelectToolAction.DRAW_TEXT) { >+ rgb = SelectToolAction.int2rgb(drawTextToolbar.getIntgerCustom()); >+ } else { >+ rgb = SelectToolAction.int2rgb(drawColorToolbar.getSelect()); >+ } >+ history[4] = (rgb.red << 16) + (rgb.green << 8) + rgb.blue; >+ historyDrawTool.add(history); >+ historyDrawText.add(new StringBuffer()); >+ if (drawTool == SelectToolAction.DRAW_TEXT) { >+ FontData fontData = new FontData(drawTextToolbar.getStringCustom()); >+ historyDrawFont.add(fontData.toString()); >+ } else { >+ historyDrawFont.add(""); //$NON-NLS-1$ >+ } >+ historyCheckpoint = historyDrawTool.size(); >+ >+ history = new int[3]; >+ history[0] = SWT.MouseDown; >+ history[1] = scaledX; >+ history[2] = scaledY; >+ historyMouseEvent.add(history); >+ undoAction.setEnabled(true); >+ >+ if (drawTool != SelectToolAction.DRAW_FREE) { >+ Display display = getShell().getDisplay(); >+ previousImage = new Image(display, workImage.getBounds()); >+ GC gc = new GC(previousImage); >+ gc.drawImage(workImage, 0, 0); >+ gc.dispose(); >+ } >+ >+ if (drawTool != SelectToolAction.DRAW_TEXT) { >+ workImageGC.setLineStyle(lineTypeToolbar.getSelect()); >+ workImageGC.setLineWidth(lineBoldToolbar.getSelect()); >+ workImageGC.setForeground(new Color(getShell().getDisplay(), >+ SelectToolAction.int2rgb(drawColorToolbar.getSelect()))); >+ } else { >+ workImageGC.setLineStyle(SWT.LINE_DOT); >+ workImageGC.setLineWidth(1); >+ workImageGC.setForeground(new Color(getShell().getDisplay(), 0, 0, 0)); >+ } >+ > startPoint = new Point(scaledX, scaledY); > drawMarkLine(scaledX, scaledY); > canvas.setCursor(cursors.get(CURSOR_MARK_TOOL)); >@@ -723,15 +1231,17 @@ > > // Check the most appropriate action to follow; first check if I'm on some grab point > if (currentSelection != null) { >- for (GrabPoint point : grabPoints) { >- if (point.grabArea.contains(e.x, e.y)) { >- originalSelection = currentSelection; >- currentAction = EditorAction.RESIZING_SELECTION; >- resizableSides = point.resizableSides; >- startPoint = new Point(scaledX, scaledY); >- canvas.redraw(); >- return; >+ int info = getGrabPoint(e.x, e.y); >+ if (info >= 0) { >+ originalSelection = currentSelection; >+ currentAction = EditorAction.RESIZING_SELECTION; >+ resizableSides = new HashSet<SelectionSide>(); >+ for (SelectionSide side : grabPointResizableSides[info]) { >+ resizableSides.add(side); > } >+ startPoint = new Point(scaledX, scaledY); >+ canvas.redraw(); >+ return; > } > } > >@@ -749,12 +1259,10 @@ > currentAction = EditorAction.SELECTING; > currentSelection = null; > startPoint = new Point(scaledX, scaledY); >- setUpGrabPoints(); >+ > canvas.redraw(); > } >- > }); >- > } > > private void clearSelection() { >@@ -779,7 +1287,7 @@ > * Calling this method under other circumstances may lead to strange behavior in the scrolled composite > */ > private void refreshCanvasSize() { >- if (fitAction.isChecked()) { >+ if (fitAction.getSelect() == SelectToolAction.ZOOM_FIT) { > // This little hack is necessary to get the client area without scrollbars; > // they'll be automatically restored if necessary after Canvas.setBounds() > scrolledComposite.getHorizontalBar().setVisible(false); >@@ -798,16 +1306,142 @@ > } > canvas.setBounds(bounds); > } else { >- scaleFactor = 1.0; >+ scaleFactor = fitAction.getSelect(); // 50, 100, 200, 400 or 800 >+ scaleFactor = scaleFactor / 100; > Rectangle bounds = scrolledComposite.getClientArea(); > if (workImage != null) { > Rectangle imageBounds = workImage.getBounds(); >- bounds.width = imageBounds.width; >- bounds.height = imageBounds.height; >+ bounds.width = (int) Math.round(imageBounds.width * scaleFactor); >+ bounds.height = (int) Math.round(imageBounds.height * scaleFactor); > } > canvas.setBounds(bounds); > } >- setUpGrabPoints(); >+ >+ canvas.redraw(); >+ } >+ >+ private void updateAnnotationHistory() { >+ int[] history; >+ if (historyCheckpoint < historyDrawTool.size()) { >+ history = historyDrawTool.get(historyCheckpoint); >+ while (history[0] < historyMouseEvent.size()) { >+ historyMouseEvent.remove(historyMouseEvent.size() - 1); >+ } >+ while (historyCheckpoint < historyDrawTool.size()) { >+ historyDrawTool.remove(historyDrawTool.size() - 1); >+ } >+ while (historyCheckpoint < historyDrawText.size()) { >+ historyDrawText.remove(historyDrawText.size() - 1); >+ } >+ while (historyCheckpoint < historyDrawFont.size()) { >+ historyDrawFont.remove(historyDrawFont.size() - 1); >+ } >+ redoAction.setEnabled(false); >+ } >+ >+ undoAction.setEnabled(historyCheckpoint > 0); >+ } >+ >+ /** >+ * Draw Annotation with history >+ */ >+ private void drawAnnotationHistory() { >+ workImageGC.drawImage(originalImage, 0, 0); >+ Color backBackground = workImageGC.getBackground(); >+ Color backForeground = workImageGC.getForeground(); >+ int backLineStyle = workImageGC.getLineStyle(); >+ int backLineWidth = workImageGC.getLineWidth(); >+ int[] history; >+ for (int c = 0; c < historyCheckpoint; c++) { >+ history = historyDrawTool.get(c); >+ int toolKind = history[1]; >+ int boldlKind = history[3]; >+ workImageGC.setLineStyle(history[2]); >+ workImageGC.setLineWidth(boldlKind); >+ workImageGC.setForeground(new Color(getShell().getDisplay(), // >+ history[4] >> 16, // >+ (history[4] >> 8) & 0x00ff, // >+ history[4] & 0x00ff)); >+ >+ int h = history[0]; >+ history = historyMouseEvent.get(h); >+ int start_x = history[1]; >+ int start_y = history[2]; >+ for (h++; h < historyMouseEvent.size(); h++) { >+ history = historyMouseEvent.get(h); >+ if (history[0] == SWT.MouseUp) { >+ break; >+ } >+ int x = history[1]; >+ int y = history[2]; >+ if (toolKind == SelectToolAction.DRAW_FREE) { >+ workImageGC.drawLine(start_x, start_y, x, y); >+ start_x = x; >+ start_y = y; >+ } else { >+ if (start_x == x && start_y == y) { >+ workImageGC.drawLine(start_x, start_y, x, y); >+ } else { >+ int rounded; >+ int width = x - start_x; >+ int height = y - start_y; >+ switch (toolKind) { >+ case SelectToolAction.DRAW_LINE: >+ workImageGC.drawLine(start_x, start_y, x, y); >+ break; >+ case SelectToolAction.DRAW_ARROW1: >+ workImageGC.setBackground(workImageGC.getForeground()); >+ drawArrowLine(start_x, start_y, x, y, false); >+ break; >+ case SelectToolAction.DRAW_ARROW2: >+ workImageGC.setBackground(workImageGC.getForeground()); >+ drawArrowLine(start_x, start_y, x, y, true); >+ break; >+ case SelectToolAction.DRAW_BOX: >+ workImageGC.drawRectangle(start_x, start_y, width, height); >+ break; >+ case SelectToolAction.DRAW_RBOX: >+ rounded = boldlKind * 8; >+ workImageGC.drawRoundRectangle(start_x, start_y, width, height, rounded, rounded); >+ break; >+ case SelectToolAction.DRAW_OVAL: >+ workImageGC.drawOval(start_x, start_y, width, height); >+ break; >+ case SelectToolAction.DRAW_FILL_BOX: >+ workImageGC.setBackground(workImageGC.getForeground()); >+ workImageGC.fillRectangle(start_x, start_y, width, height); >+ break; >+ case SelectToolAction.DRAW_FILL_RBOX: >+ rounded = boldlKind * 8; >+ workImageGC.setBackground(workImageGC.getForeground()); >+ workImageGC.fillRoundRectangle(start_x, start_y, width, height, rounded, rounded); >+ break; >+ case SelectToolAction.DRAW_FILL_OVAL: >+ workImageGC.setBackground(workImageGC.getForeground()); >+ workImageGC.fillOval(start_x, start_y, width, height); >+ break; >+ case SelectToolAction.DRAW_TEXT: >+ StringBuffer text = historyDrawText.get(c); >+ { >+ Font backFont = workImageGC.getFont(); >+ FontData fontData = new FontData(historyDrawFont.get(c)); >+ workImageGC.setFont(new Font(getShell().getDisplay(), fontData)); >+ workImageGC.setClipping(start_x, start_y, width, height); >+ workImageGC.drawText(text.toString(), start_x, start_y, true); >+ workImageGC.setClipping((Rectangle) null); >+ workImageGC.setFont(backFont); >+ } >+ break; >+ } >+ } >+ } >+ } >+ } >+ workImageGC.setBackground(backBackground); >+ workImageGC.setForeground(backForeground); >+ workImageGC.setLineStyle(backLineStyle); >+ workImageGC.setLineWidth(backLineWidth); >+ > canvas.redraw(); > } > >@@ -818,7 +1452,7 @@ > if (currentSelection == null) { > return; > } >- Rectangle scaledSelection = getScaledSelection(); >+ Rectangle inside = getScaledSelection(); > > // Draw shadow > gc.setBackground(CommonColors.GRAY_MID); >@@ -827,7 +1461,7 @@ > > Region invertedSelection = new Region(); > invertedSelection.add(canvas.getClientArea()); >- invertedSelection.subtract(scaledSelection); >+ invertedSelection.subtract(inside); > gc.setClipping(invertedSelection); > gc.fillRectangle(canvas.getClientArea()); > gc.setClipping((Region) null); >@@ -838,30 +1472,169 @@ > // Draw selection rectangle > gc.setLineStyle(SWT.LINE_SOLID); > gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); >- gc.drawRectangle(scaledSelection); >+ gc.drawRectangle(inside); > >- // Draw grab points >- gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE)); >- gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK)); >- for (GrabPoint point : grabPoints) { >- gc.fillRectangle(point.grabArea); >- gc.drawRectangle(point.grabArea); >- } >+// // Draw grab points >+// gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE)); >+// gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK)); >+// for (GrabPoint point : grabPoints) { >+// gc.fillRectangle(point.grabArea); >+// gc.drawRectangle(point.grabArea); >+// } >+ gc.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); >+ Rectangle outside = getOutsideSelection(inside); >+ gc.drawRectangle(outside); >+ gc.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); >+ gc.fillRectangle(outside.x, outside.y, // >+ SQUARE_SIZE * 6, SQUARE_SIZE * 2); >+ gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 6, outside.y, // >+ SQUARE_SIZE * 6, SQUARE_SIZE * 2); >+ gc.fillRectangle(outside.x, outside.y, // >+ SQUARE_SIZE * 2, SQUARE_SIZE * 6); >+ gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 2, outside.y, // >+ SQUARE_SIZE * 2, SQUARE_SIZE * 6); >+ gc.fillRectangle(outside.x, outside.y + outside.height - SQUARE_SIZE * 6, // >+ SQUARE_SIZE * 2, SQUARE_SIZE * 6); >+ gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 2, outside.y + outside.height - SQUARE_SIZE * 6, // >+ SQUARE_SIZE * 2, SQUARE_SIZE * 6); >+ gc.fillRectangle(outside.x, outside.y + outside.height - SQUARE_SIZE * 2, // >+ SQUARE_SIZE * 6, SQUARE_SIZE * 2); >+ gc.fillRectangle(outside.x + outside.width - SQUARE_SIZE * 6, outside.y + outside.height - SQUARE_SIZE * 2, // >+ SQUARE_SIZE * 6, SQUARE_SIZE * 2); > } > > /** >- * Connects the previous mark point to the new reference point, by drawing a new line >+ * Connects the previous mark point to the new reference point, by drawing a new line, rectangle or oval > */ > private void drawMarkLine(int x, int y) { > if (startPoint != null) { > clearAction.setEnabled(true); >- workImageGC.drawLine(startPoint.x, startPoint.y, x, y); >- startPoint.x = x; >- startPoint.y = y; >+ int drawTool = getSelectDrawToolbar(); >+ if (drawTool == SelectToolAction.DRAW_FREE) { >+ workImageGC.drawLine(startPoint.x, startPoint.y, x, y); >+ startPoint.x = x; >+ startPoint.y = y; >+ } else { >+ workImageGC.drawImage(previousImage, 0, 0); >+ if (startPoint.x == x && startPoint.y == y) { >+ workImageGC.drawLine(startPoint.x, startPoint.y, x, y); >+ } else { >+ Color backColor; >+ Color markColor; >+ int rounded; >+ int width = x - startPoint.x; >+ int height = y - startPoint.y; >+ switch (drawTool) { >+ case SelectToolAction.DRAW_LINE: >+ workImageGC.drawLine(startPoint.x, startPoint.y, x, y); >+ break; >+ case SelectToolAction.DRAW_ARROW1: >+ backColor = workImageGC.getBackground(); >+ markColor = new Color(getShell().getDisplay(), >+ SelectToolAction.int2rgb(drawColorToolbar.getSelect())); >+ workImageGC.setBackground(markColor); >+ drawArrowLine(startPoint.x, startPoint.y, x, y, false); >+ workImageGC.setBackground(backColor); >+ break; >+ case SelectToolAction.DRAW_ARROW2: >+ backColor = workImageGC.getBackground(); >+ markColor = new Color(getShell().getDisplay(), >+ SelectToolAction.int2rgb(drawColorToolbar.getSelect())); >+ workImageGC.setBackground(markColor); >+ drawArrowLine(startPoint.x, startPoint.y, x, y, true); >+ workImageGC.setBackground(backColor); >+ break; >+ case SelectToolAction.DRAW_BOX: >+ workImageGC.drawRectangle(startPoint.x, startPoint.y, width, height); >+ break; >+ case SelectToolAction.DRAW_RBOX: >+ rounded = lineBoldToolbar.getSelect() * 8; >+ workImageGC.drawRoundRectangle(startPoint.x, startPoint.y, width, height, rounded, rounded); >+ break; >+ case SelectToolAction.DRAW_OVAL: >+ workImageGC.drawOval(startPoint.x, startPoint.y, width, height); >+ break; >+ case SelectToolAction.DRAW_FILL_BOX: >+ backColor = workImageGC.getBackground(); >+ markColor = new Color(getShell().getDisplay(), >+ SelectToolAction.int2rgb(drawColorToolbar.getSelect())); >+ workImageGC.setBackground(markColor); >+ workImageGC.fillRectangle(startPoint.x, startPoint.y, width, height); >+ workImageGC.setBackground(backColor); >+ break; >+ case SelectToolAction.DRAW_FILL_RBOX: >+ rounded = lineBoldToolbar.getSelect() * 8; >+ backColor = workImageGC.getBackground(); >+ markColor = new Color(getShell().getDisplay(), >+ SelectToolAction.int2rgb(drawColorToolbar.getSelect())); >+ workImageGC.setBackground(markColor); >+ workImageGC.fillRoundRectangle(startPoint.x, startPoint.y, width, height, rounded, rounded); >+ workImageGC.setBackground(backColor); >+ break; >+ case SelectToolAction.DRAW_FILL_OVAL: >+ backColor = workImageGC.getBackground(); >+ markColor = new Color(getShell().getDisplay(), >+ SelectToolAction.int2rgb(drawColorToolbar.getSelect())); >+ workImageGC.setBackground(markColor); >+ workImageGC.fillOval(startPoint.x, startPoint.y, width, height); >+ workImageGC.setBackground(backColor); >+ break; >+ case SelectToolAction.DRAW_TEXT: >+ workImageGC.fillRectangle(startPoint.x, startPoint.y, width, height); >+ workImageGC.drawRectangle(startPoint.x, startPoint.y, width, height); >+ break; >+ } >+ } >+ } > canvas.redraw(); > } > } > >+ public void drawArrowLine(int xs, int ys, int xe, int ye, boolean bothsides) { >+ int width = xe - xs, height = ye - ys; >+ int bold = workImageGC.getLineWidth(); >+ int leng = (bold == 8) ? bold * 4 : (bold == 4) ? bold * 6 : (bold == 2) ? bold * 8 : bold * 10; >+ double delta = Math.PI / 6.0; >+ double theta = Math.atan2(height, width); >+ >+ // Draw line >+ if (bothsides) { >+ workImageGC.drawLine( // >+ xs + (int) (leng / 2 * Math.cos(theta)), // >+ ys + (int) (leng / 2 * Math.sin(theta)), // >+ xe - (int) (leng / 2 * Math.cos(theta)), // >+ ye - (int) (leng / 2 * Math.sin(theta))); >+ } else { >+ workImageGC.drawLine( // >+ xs, // >+ ys, // >+ xe - (int) (leng / 2 * Math.cos(theta)), // >+ ye - (int) (leng / 2 * Math.sin(theta))); >+ } >+ >+ // Draw ending side arrow >+ workImageGC.setLineWidth(1); >+ >+ int[] point = { xe, ye, // >+ xe - (int) (leng * Math.cos(theta - delta)), // >+ ye - (int) (leng * Math.sin(theta - delta)), // >+ xe - (int) (leng * Math.cos(theta + delta)), // >+ ye - (int) (leng * Math.sin(theta + delta)) }; >+ workImageGC.fillPolygon(point); >+ >+ // Draw starting side arrow >+ if (bothsides) { >+ int[] point2 = { xs, ys, // >+ xs + (int) (leng * Math.cos(theta - delta)), // >+ ys + (int) (leng * Math.sin(theta - delta)), // >+ xs + (int) (leng * Math.cos(theta + delta)), // >+ ys + (int) (leng * Math.sin(theta + delta)) }; >+ workImageGC.fillPolygon(point2); >+ } >+ >+ workImageGC.setLineWidth(bold); >+ } >+ > private static enum SelectionSide { > > LEFT, RIGHT, TOP, BOTTOM; >@@ -870,26 +1643,6 @@ > > private static final int SQUARE_SIZE = 3; > >- private static class GrabPoint { >- >- public Rectangle grabArea; >- >- public int cursorType; >- >- public Set<SelectionSide> resizableSides; >- >- public static GrabPoint createGrabPoint(int x, int y, int cursorType, Set<SelectionSide> resizableSides) { >- GrabPoint point = new GrabPoint(); >- point.grabArea = new Rectangle(x - SQUARE_SIZE, y - SQUARE_SIZE, SQUARE_SIZE * 2 + 1, SQUARE_SIZE * 2 + 1); >- point.cursorType = cursorType; >- point.resizableSides = resizableSides; >- return point; >- } >- >- } >- >- private final List<GrabPoint> grabPoints = new ArrayList<GrabPoint>(8); >- > /** > * Creates the final screenshot > * >Index: src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImages.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImages.java,v >retrieving revision 1.11 >diff -u -r1.11 CommonImages.java >--- src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImages.java 3 Dec 2008 02:39:31 -0000 1.11 >+++ src/org/eclipse/mylyn/internal/provisional/commons/ui/CommonImages.java 9 May 2009 08:25:43 -0000 >@@ -45,6 +45,8 @@ > > private static final String T_OVR = "ovr16"; //$NON-NLS-1$ > >+ private static final String T_DRAW = "draw16"; //$NON-NLS-1$ >+ > // Priorities > > public static final ImageDescriptor PRIORITY_1 = create(T_OBJ, "priority-1.gif"); //$NON-NLS-1$ >@@ -155,6 +157,30 @@ > > public static final ImageDescriptor EDIT = create(T_TOOL, "edit.gif"); //$NON-NLS-1$ > >+ public static final ImageDescriptor EDIT_FREE = create(T_DRAW, "edit_free.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_LINE = create(T_DRAW, "edit_line.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_BOX = create(T_DRAW, "edit_box.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_RBOX = create(T_DRAW, "edit_rbox.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_OVAL = create(T_DRAW, "edit_oval.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_FILL_BOX = create(T_DRAW, "edit_fill_box.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_FILL_RBOX = create(T_DRAW, "edit_fill_rbox.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_FILL_OVAL = create(T_DRAW, "edit_fill_oval.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_ARROW1 = create(T_DRAW, "edit_arrow1.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_ARROW2 = create(T_DRAW, "edit_arrow2.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_UNDO = create(T_TOOL, "undo_edit.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor EDIT_REDO = create(T_TOOL, "redo_edit.gif"); //$NON-NLS-1$ >+ > public static final ImageDescriptor CUT = create(T_TOOL, "cut.gif"); //$NON-NLS-1$ > > public static final ImageDescriptor STATUS_NORMAL = create(T_EVIEW, "status-normal.gif"); //$NON-NLS-1$ >@@ -201,6 +227,32 @@ > > public static final ImageDescriptor FIND = create(T_TOOL, "find.gif"); //$NON-NLS-1$ > >+ public static final ImageDescriptor FILE_OBJ = create(T_TOOL, "file_obj.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor CLIPBOARD_OBJ = create(T_TOOL, "clipboard_obj.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor MINITOR_OBJ = create(T_TOOL, "monitor_obj.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor LINE_SOLD = create(T_DRAW, "line_sold.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor LINE_DOT = create(T_DRAW, "line_dot.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor LINE_DASH = create(T_DRAW, "line_dash.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor LINE_DASH1D = create(T_DRAW, "line_dash1d.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor LINE_DASH2D = create(T_DRAW, "line_dash2d.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor LINE_BOLD1 = create(T_DRAW, "line_bold1.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor LINE_BOLD2 = create(T_DRAW, "line_bold2.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor LINE_BOLD4 = create(T_DRAW, "line_bold4.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor LINE_BOLD8 = create(T_DRAW, "line_bold8.gif"); //$NON-NLS-1$ >+ >+ public static final ImageDescriptor SEL_RECT = create(T_TOOL, "select_rect.gif"); //$NON-NLS-1$ >+ > private static ImageDescriptor create(String prefix, String name) { > try { > return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name)); >Index: src/org/eclipse/mylyn/internal/commons/ui/messages.properties >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/commons/ui/messages.properties,v >retrieving revision 1.2 >diff -u -r1.2 messages.properties >--- src/org/eclipse/mylyn/internal/commons/ui/messages.properties 10 Jan 2009 08:39:37 -0000 1.2 >+++ src/org/eclipse/mylyn/internal/commons/ui/messages.properties 9 May 2009 08:25:42 -0000 >@@ -15,15 +15,56 @@ > > ScreenshotCreationPage_After_capturing=After capturing, you can crop the image and make drawings on it. This window will not be captured. > ScreenshotCreationPage_Annotate=&Annotate >-ScreenshotCreationPage_Capture_Desktop=Capture Desktop >-ScreenshotCreationPage_Capture_Desktop_C=&Capture Desktop >+ScreenshotCreationPage_Capture_Desktop=Capture Desktop, Clipboard or File >+ScreenshotCreationPage_Capture_Desktop_C=&Capture > ScreenshotCreationPage_CAPTURE_SCRRENSHOT=Capture Screenshot >-ScreenshotCreationPage_Change_pen_color=Change pen color > ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image=Clear all annotations made on screenshot image >-ScreenshotCreationPage_Clear_Annotations=C&lear Annotations >+ScreenshotCreationPage_Clear=C&lear >+ScreenshotCreationPage_Undo=&Undo >+ScreenshotCreationPage_Undo_annotation=Undo annotation >+ScreenshotCreationPage_Redo=Re&do >+ScreenshotCreationPage_Redo_annotation=Redo annotation > ScreenshotCreationPage_Crop=Crop > ScreenshotCreationPage_Crop_R=C&rop > ScreenshotCreationPage_DRAW_ANNOTATION_ON_SCREENSHOT_IMAGE=Draw annotations on screenshot image > ScreenshotCreationPage_Fit_Image=Fit Image >-ScreenshotCreationPage_Fit_Image_F=&Fit Image >+#ScreenshotCreationPage_Fit_Image_F=&Fit Image >+ScreenshotCreationPage_Fit_Image_F=&Fit > ScreenshotCreationPage_NOTE_THAT_YOU_CONTINUTE=Note that you can continue to interact with the workbench in order to set up the screenshot. >+ScreenshotCreationPage_Show_Line_Type_Selector=Show Line Type Selector >+ScreenshotCreationPage_Show_Line_Bold_Selector=Show Line Bold Selector >+ >+SelectToolAction_Font_Bold=, Bold >+SelectToolAction_Font_Italic=, Italic >+SelectToolAction_Font_Name_Size={0}, {1} pt >+SelectToolAction_1dot=1 dot >+SelectToolAction_2dots=2 dots >+SelectToolAction_4dots=4 dots >+SelectToolAction_8dots=8 dots >+SelectToolAction_Clipboard=Clipboard >+SelectToolAction_Desktop=Desktop >+SelectToolAction_File=File... >+SelectToolAction_Selected_Rectangle=Selected Rectangle >+SelectToolAction_Rectangle=Rectangle >+SelectToolAction_Round_Rectangle=Round Rectangle >+SelectToolAction_Oval=Oval >+SelectToolAction_Fill_Rectangle=Fill Rectangle >+SelectToolAction_Fill_Round_Rectangle=Fill Round Rectangle >+SelectToolAction_Fill_Oval=Fill Oval >+SelectToolAction_Free=Free >+SelectToolAction_Line=Line >+SelectToolAction_Single_Side_Arrow=Single Side Arrow >+SelectToolAction_Both_Side_Arrow=Both Side Arrow >+SelectToolAction_Dashed_Line=Dashed Line >+SelectToolAction_Dashed_Line_1_dot=1 dots Dashed Line >+SelectToolAction_Dashed_Line_2_dots=2 dots Dashed Line >+SelectToolAction_Dotted_Line=Dotted Line >+SelectToolAction_Solid_Line=Solid Line >+SelectToolAction_Fit=Fit >+SelectToolAction_ZoomHalf=50% >+SelectToolAction_Zoom1X=100% >+SelectToolAction_Zoom2X=200% >+SelectToolAction_Zoom4X=400% >+SelectToolAction_Zoom8X=800% >+SelectToolAction_Font_=Font... >+SelectToolAction_Color_=Color... >Index: src/org/eclipse/mylyn/internal/commons/ui/Messages.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.commons.ui/src/org/eclipse/mylyn/internal/commons/ui/Messages.java,v >retrieving revision 1.2 >diff -u -r1.2 Messages.java >--- src/org/eclipse/mylyn/internal/commons/ui/Messages.java 10 Jan 2009 08:39:37 -0000 1.2 >+++ src/org/eclipse/mylyn/internal/commons/ui/Messages.java 9 May 2009 08:25:42 -0000 >@@ -53,11 +53,17 @@ > > public static String ScreenshotCreationPage_CAPTURE_SCRRENSHOT; > >- public static String ScreenshotCreationPage_Change_pen_color; >- > public static String ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image; > >- public static String ScreenshotCreationPage_Clear_Annotations; >+ public static String ScreenshotCreationPage_Clear; >+ >+ public static String ScreenshotCreationPage_Undo; >+ >+ public static String ScreenshotCreationPage_Undo_annotation; >+ >+ public static String ScreenshotCreationPage_Redo; >+ >+ public static String ScreenshotCreationPage_Redo_annotation; > > public static String ScreenshotCreationPage_Crop; > >@@ -70,4 +76,76 @@ > public static String ScreenshotCreationPage_Fit_Image_F; > > public static String ScreenshotCreationPage_NOTE_THAT_YOU_CONTINUTE; >+ >+ public static String ScreenshotCreationPage_Show_Line_Type_Selector; >+ >+ public static String ScreenshotCreationPage_Show_Line_Bold_Selector; >+ >+ public static String SelectToolAction_Font_Bold; >+ >+ public static String SelectToolAction_Font_Italic; >+ >+ public static String SelectToolAction_Font_Name_Size; >+ >+ public static String SelectToolAction_1dot; >+ >+ public static String SelectToolAction_2dots; >+ >+ public static String SelectToolAction_4dots; >+ >+ public static String SelectToolAction_8dots; >+ >+ public static String SelectToolAction_Clipboard; >+ >+ public static String SelectToolAction_Desktop; >+ >+ public static String SelectToolAction_File; >+ >+ public static String SelectToolAction_Rectangle; >+ >+ public static String SelectToolAction_Round_Rectangle; >+ >+ public static String SelectToolAction_Oval; >+ >+ public static String SelectToolAction_Fill_Rectangle; >+ >+ public static String SelectToolAction_Fill_Round_Rectangle; >+ >+ public static String SelectToolAction_Fill_Oval; >+ >+ public static String SelectToolAction_Free; >+ >+ public static String SelectToolAction_Line; >+ >+ public static String SelectToolAction_Single_Side_Arrow; >+ >+ public static String SelectToolAction_Both_Side_Arrow; >+ >+ public static String SelectToolAction_Dashed_Line; >+ >+ public static String SelectToolAction_Dashed_Line_1_dot; >+ >+ public static String SelectToolAction_Dashed_Line_2_dots; >+ >+ public static String SelectToolAction_Dotted_Line; >+ >+ public static String SelectToolAction_Solid_Line; >+ >+ public static String SelectToolAction_Fit; >+ >+ public static String SelectToolAction_ZoomHalf; >+ >+ public static String SelectToolAction_Zoom1X; >+ >+ public static String SelectToolAction_Zoom2X; >+ >+ public static String SelectToolAction_Zoom4X; >+ >+ public static String SelectToolAction_Zoom8X; >+ >+ public static String SelectToolAction_Selected_Rectangle; >+ >+ public static String SelectToolAction_Font_; >+ >+ public static String SelectToolAction_Color_; > } >Index: src/org/eclipse/mylyn/internal/provisional/commons/ui/SelectToolAction.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/provisional/commons/ui/SelectToolAction.java >diff -N src/org/eclipse/mylyn/internal/provisional/commons/ui/SelectToolAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/provisional/commons/ui/SelectToolAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,858 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Tasktop Technologies and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Hiroyuki Inaba - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.mylyn.internal.provisional.commons.ui; >+ >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.jface.action.Action; >+import org.eclipse.jface.action.ActionContributionItem; >+import org.eclipse.jface.action.IMenuCreator; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.mylyn.internal.commons.ui.Messages; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.dnd.Clipboard; >+import org.eclipse.swt.dnd.ImageTransfer; >+import org.eclipse.swt.events.MouseAdapter; >+import org.eclipse.swt.events.MouseEvent; >+import org.eclipse.swt.graphics.Color; >+import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.FontData; >+import org.eclipse.swt.graphics.GC; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.ImageData; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.RGB; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.ColorDialog; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.swt.widgets.FileDialog; >+import org.eclipse.swt.widgets.FontDialog; >+import org.eclipse.swt.widgets.Listener; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.MenuItem; >+import org.eclipse.swt.widgets.ToolItem; >+import org.eclipse.swt.widgets.Widget; >+ >+public class SelectToolAction extends Action implements IMenuCreator { >+ >+ public static final int CAPTURE_DROP_DOWN_MENU = 1; >+ >+ public static final int ZOOM_DROP_DOWN_MENU = 2; >+ >+ public static final int DRAWLINE_TOOLBAR = 3; >+ >+ public static final int DRAWARROW_TOOLBAR = 4; >+ >+ public static final int DRAWBOX_TOOLBAR = 5; >+ >+ public static final int DRAWTEXT_TOOLBAR = 6; >+ >+ public static final int LINETYPE_TOOLBAR = 7; >+ >+ public static final int LINEBOLD_TOOLBAR = 8; >+ >+ public static final int COLOR_TOOLBAR = 9; >+ >+ public SelectToolAction(Composite parent, int tool) { >+ this(parent, "", tool); //$NON-NLS-1$ >+ } >+ >+ public SelectToolAction(String label, int tool) { >+ this(null, label, tool); >+ } >+ >+ public SelectToolAction(Composite parent, String label, int tool) { >+ super(label, AS_DROP_DOWN_MENU); >+ setMenuCreator(this); >+ showMenuAlways = true; >+ this.parent = parent; >+ setToolAction(tool); >+ } >+ >+ private void setToolAction(int tool) { >+ if (tool == CAPTURE_DROP_DOWN_MENU) { >+ selectedItemID = CAPTURE_DESKTOP; >+ initMenu(tool, new ToolActionItem[] { >+ new ToolActionItem(CAPTURE_DESKTOP, Messages.SelectToolAction_Desktop, CommonImages.MINITOR_OBJ), // >+ new ToolActionItem(CAPTURE_CLIPBOARD, Messages.SelectToolAction_Clipboard, >+ CommonImages.CLIPBOARD_OBJ), // >+ new ToolActionItem(CAPTURE_FILE, Messages.SelectToolAction_File, CommonImages.FILE_OBJ), >+ new ToolActionItem(CAPTURE_RECTANGLE, Messages.SelectToolAction_Selected_Rectangle, >+ CommonImages.SEL_RECT) }); >+ return; >+ } >+ >+ if (tool == ZOOM_DROP_DOWN_MENU) { >+ selectedItemID = ZOOM_FIT; >+ initMenu(tool, new ToolActionItem[] { new ToolActionItem(ZOOM_FIT, Messages.SelectToolAction_Fit, null), >+ new ToolActionItem(50, Messages.SelectToolAction_ZoomHalf, null), >+ new ToolActionItem(100, Messages.SelectToolAction_Zoom1X, null), >+ new ToolActionItem(200, Messages.SelectToolAction_Zoom2X, null), >+ new ToolActionItem(400, Messages.SelectToolAction_Zoom4X, null), >+ new ToolActionItem(800, Messages.SelectToolAction_Zoom8X, null) }); >+ return; >+ } >+ >+ if (tool == LINETYPE_TOOLBAR) { >+ selectedItemID = SWT.LINE_SOLID; >+ initBar(tool, new ToolActionItem[] { >+ new ToolActionItem(SWT.LINE_SOLID, Messages.SelectToolAction_Solid_Line, CommonImages.LINE_SOLD), >+ new ToolActionItem(SWT.LINE_DOT, Messages.SelectToolAction_Dotted_Line, CommonImages.LINE_DOT), >+ new ToolActionItem(SWT.LINE_DASH, Messages.SelectToolAction_Dashed_Line, CommonImages.LINE_DASH), >+ new ToolActionItem(SWT.LINE_DASHDOT, Messages.SelectToolAction_Dashed_Line_1_dot, >+ CommonImages.LINE_DASH1D), >+ new ToolActionItem(SWT.LINE_DASHDOTDOT, Messages.SelectToolAction_Dashed_Line_2_dots, >+ CommonImages.LINE_DASH2D) }); >+ return; >+ } >+ >+ if (tool == DRAWLINE_TOOLBAR) { >+ showSelection = true; >+ selectedItemID = DRAW_FREE; >+ initBar(tool, new ToolActionItem[] { >+ new ToolActionItem(DRAW_FREE, Messages.SelectToolAction_Free, CommonImages.EDIT_FREE), >+ new ToolActionItem(DRAW_LINE, Messages.SelectToolAction_Line, CommonImages.EDIT_LINE) }); >+ return; >+ } >+ if (tool == DRAWARROW_TOOLBAR) { >+ showSelection = true; >+ selectedItemID = DRAW_ARROW1; >+ initBar(tool, >+ new ToolActionItem[] { >+ new ToolActionItem(DRAW_ARROW1, Messages.SelectToolAction_Single_Side_Arrow, >+ CommonImages.EDIT_ARROW1), >+ new ToolActionItem(DRAW_ARROW2, Messages.SelectToolAction_Both_Side_Arrow, >+ CommonImages.EDIT_ARROW2) }); >+ selectedItemID = -1; >+ return; >+ } >+ if (tool == DRAWBOX_TOOLBAR) { >+ showSelection = true; >+ selectedItemID = DRAW_RBOX; >+ initBar(tool, >+ new ToolActionItem[] { >+ new ToolActionItem(DRAW_BOX, Messages.SelectToolAction_Rectangle, CommonImages.EDIT_BOX), >+ new ToolActionItem(DRAW_RBOX, Messages.SelectToolAction_Round_Rectangle, >+ CommonImages.EDIT_RBOX), >+ new ToolActionItem(DRAW_OVAL, Messages.SelectToolAction_Oval, CommonImages.EDIT_OVAL), >+ new ToolActionItem(DRAW_FILL_BOX, Messages.SelectToolAction_Fill_Rectangle, >+ CommonImages.EDIT_FILL_BOX), >+ new ToolActionItem(DRAW_FILL_RBOX, Messages.SelectToolAction_Fill_Round_Rectangle, >+ CommonImages.EDIT_FILL_RBOX), >+ new ToolActionItem(DRAW_FILL_OVAL, Messages.SelectToolAction_Fill_Oval, >+ CommonImages.EDIT_FILL_OVAL) }); >+ selectedItemID = -1; >+ return; >+ } >+ if (tool == DRAWTEXT_TOOLBAR) { >+ showSelection = true; >+ selectedItemID = DRAW_TEXT; >+ FontData fontData = parent.getShell().getFont().getFontData()[0]; >+ stringCustom = fontData.toString(); >+ intgerCustom = rgb2int(255, 0, 0); >+ selectedItemID = intgerCustom; >+ initFont(tool); >+ selectedItemID = -1; >+ return; >+ } >+ >+ if (tool == LINEBOLD_TOOLBAR) { >+ selectedItemID = 4; >+ initBar(tool, new ToolActionItem[] { >+ new ToolActionItem(1, Messages.SelectToolAction_1dot, CommonImages.LINE_BOLD1), >+ new ToolActionItem(2, Messages.SelectToolAction_2dots, CommonImages.LINE_BOLD2), >+ new ToolActionItem(4, Messages.SelectToolAction_4dots, CommonImages.LINE_BOLD4), >+ new ToolActionItem(8, Messages.SelectToolAction_8dots, CommonImages.LINE_BOLD8) }); >+ return; >+ } >+ >+ if (tool == COLOR_TOOLBAR) { >+ intgerCustom = rgb2int(255, 85, 85); >+ selectedItemID = intgerCustom; >+ initColor(tool); >+ return; >+ } >+ } >+ >+ private void initBar(int tool, ToolActionItem[] items) { >+ this.items = items; >+ setId(tool + ""); //$NON-NLS-1$ >+ toolButton = new ToolComposite(parent, SWT.CASCADE) { >+ >+ @Override >+ public void clickBody() { >+ selectItem(getToolTipText(), null); >+ } >+ >+ @Override >+ public void clickMenu(int x, int y) { >+ dropDownMenu = new Menu(parent.getShell(), SWT.POP_UP); >+ addActionsToMenu(); >+ Point p = parent.toDisplay(x, y); >+ dropDownMenu.setLocation(p.x, p.y); >+ dropDownMenu.setVisible(true); >+ dropDownMenu = null; >+ } >+ >+ @Override >+ public boolean isSelect() { >+ return (selectedItemID >= 0); >+ } >+ }; >+ >+ if (items != null) { >+ for (ToolActionItem actionItem : items) { >+ if (actionItem.id == selectedItemID) { >+ toolButton.setImage(actionItem.image.createImage()); >+ toolButton.setToolTipText(actionItem.label); >+ } >+ } >+ } >+ } >+ >+ private void initFont(int tool) { >+ this.items = null; >+ setId(tool + ""); //$NON-NLS-1$ >+ toolButton = new ToolComposite(parent, SWT.CASCADE) { >+ >+ @Override >+ public void clickBody() { >+ selectedItemID = DRAW_TEXT; >+ if (toolButton != null) { >+ FontData fontData = new FontData(stringCustom); >+ toolButton.setImage(createFontImage(fontData, int2rgb(intgerCustom), true)); >+ toolButton.redraw(); >+ } >+ run(); >+ } >+ >+ @Override >+ public void clickMenu(int x, int y) { >+ if (Platform.getWS().equalsIgnoreCase(Platform.WS_WIN32) >+ || Platform.getWS().equalsIgnoreCase(Platform.WS_WPF)) { >+ invokeFontDialog(); >+ } else { >+ Menu rightClickMenu = new Menu(parent.getShell(), SWT.POP_UP); >+ MenuItem menuItem = new MenuItem(rightClickMenu, SWT.PUSH); >+ menuItem.setText(Messages.SelectToolAction_Font_); >+ menuItem.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(final Event event) { >+ invokeFontDialog(); >+ } >+ }); >+ menuItem = new MenuItem(rightClickMenu, SWT.PUSH); >+ menuItem.setText(Messages.SelectToolAction_Color_); >+ menuItem.addListener(SWT.Selection, new Listener() { >+ public void handleEvent(final Event event) { >+ invokeColorDialog(); >+ } >+ }); >+ Point p = parent.toDisplay(x, y); >+ rightClickMenu.setLocation(p.x, p.y); >+ rightClickMenu.setVisible(true); >+ } >+ } >+ >+ @Override >+ public boolean isSelect() { >+ return (selectedItemID >= 0); >+ } >+ >+ public void invokeFontDialog() { >+ FontData fontData = new FontData(stringCustom); >+ FontDialog fontWindow = new FontDialog(parent.getShell()); >+ fontWindow.setFontList(new FontData[] { fontData }); >+ fontWindow.setRGB(int2rgb(intgerCustom)); >+ fontData = fontWindow.open(); >+ if (fontData != null) { >+ intgerCustom = rgb2int(fontWindow.getRGB()); >+ stringCustom = fontData.toString(); >+ toolButton.setToolTipText(font2string(fontData)); >+ clickBody(); >+ } >+ } >+ >+ public void invokeColorDialog() { >+ ColorDialog colorWindow = new ColorDialog(parent.getShell()); >+ colorWindow.setRGB(int2rgb(intgerCustom)); >+ RGB rgb = colorWindow.open(); >+ if (rgb != null) { >+ intgerCustom = rgb2int(rgb); >+ clickBody(); >+ } >+ } >+ }; >+ >+ FontData fontData = new FontData(stringCustom); >+ toolButton.setToolTipText(font2string(fontData)); >+ toolButton.setImage(createFontImage(fontData, int2rgb(intgerCustom), false)); >+ } >+ >+ private void initColor(int tool) { >+ this.items = null; >+ setId(tool + ""); //$NON-NLS-1$ >+ toolButton = new ToolComposite(parent, SWT.NONE) { >+ >+ @Override >+ public void clickMenu(int x, int y) { >+ ColorDialog colorWindow = new ColorDialog(parent.getShell()); >+ colorWindow.setRGB(int2rgb(intgerCustom)); >+ RGB rgb = colorWindow.open(); >+ if (rgb != null) { >+ intgerCustom = rgb2int(rgb); >+ selectedItemID = intgerCustom; >+ toolButton.setImage(createColorImage(int2rgb(intgerCustom))); >+ toolButton.redraw(); >+ } >+ } >+ }; >+ toolButton.setToolTipText(""); //$NON-NLS-1$ >+ toolButton.setImage(createColorImage(int2rgb(intgerCustom))); >+ } >+ >+ private Image createColorImage(RGB rgb) { >+ Display display = parent.getDisplay(); >+ Color BACKGROUND = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); >+ Color DARK_GRAY = display.getSystemColor(SWT.COLOR_DARK_GRAY); >+ int x = 16, y = 16; >+ Image image = new Image(display, x, y); >+ GC gc = new GC(image); >+ gc.setForeground(DARK_GRAY); >+ gc.setBackground(BACKGROUND); >+ gc.fillRectangle(0, 0, x, y); >+ gc.setBackground(new Color(display, rgb)); >+ gc.fillRectangle(1, 2, x - 2, y - 4); >+ gc.drawRectangle(1, 2, x - 3, y - 5); >+ gc.dispose(); >+ return image; >+ } >+ >+ private Image createFontImage(FontData fontData, RGB rgb, boolean select) { >+ Display display = parent.getDisplay(); >+ Color ButtonFace = display.getSystemColor((select) ? SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW >+ : SWT.COLOR_WIDGET_BACKGROUND); >+ int x = 16, y = 16; >+ Image image = new Image(display, x, y); >+ GC gc = new GC(image); >+ gc.setBackground(ButtonFace); >+ gc.fillRectangle(0, 0, x, y); >+ String label = "A"; //$NON-NLS-1$ >+ fontData.height = 11; >+ gc.setFont(new Font(display, fontData)); >+ gc.setForeground(new Color(display, rgb)); >+ Point sz = gc.textExtent(label); >+ gc.drawText(label, (x - sz.x) / 2, (y - sz.y) / 2 + 1, true); >+ gc.dispose(); >+ return image; >+ } >+ >+ private void initMenu(int tool, ToolActionItem[] items) { >+ this.items = items; >+ setId(tool + ""); //$NON-NLS-1$ >+ if (items != null) { >+ setImageDescriptor(items[0].image); >+ setToolTipText(items[0].label); >+ selectedItemID = items[0].id; >+ } >+ } >+ >+ private class ToolActionItem { >+ int id; >+ >+ String label; >+ >+ ImageDescriptor image; >+ >+ ToolActionItem(int id, String label, ImageDescriptor image) { >+ this.id = id; >+ this.label = label; >+ this.image = image; >+ } >+ } >+ >+ private class ToolComposite extends Composite { >+ private Image image; >+ >+ private final boolean bMenu; >+ >+ private boolean bMouse; >+ >+ private static final int S = 1; // Border for Selected rectangle >+ >+ private static final int B = 2; // Border for Shadow rectangle >+ >+ private static final int G = 3; // Gap >+ >+ private static final int M = 4; // Image width for Sub menu >+ >+ private final Point iconSize = new Point(S + B + 16 + B + S, S + B + 16 + B + S); >+ >+ private final Point maxSize = new Point(iconSize.x + G + M + G, iconSize.y); >+ >+ public ToolComposite(Composite parent, int style) { >+ super(parent, style); >+ bMenu = (style & SWT.CASCADE) != 0; >+ >+ addListener(SWT.Paint, new Listener() { >+ public void handleEvent(Event e) { >+ Color background = e.gc.getBackground(); >+ Color foreground = e.gc.getForeground(); >+ Display display = e.widget.getDisplay(); >+ Color NORMAL_SHADOW = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); >+ boolean enabled = getEnabled(); >+ if (bMouse && enabled) { >+ e.gc.setForeground(NORMAL_SHADOW); >+ if (bMenu) { >+ e.gc.drawRectangle(0, 0, maxSize.x - 1, maxSize.y - 1); >+ e.gc.drawLine(iconSize.x, 0, iconSize.x, maxSize.y); >+ } else { >+ e.gc.drawRectangle(0, 0, iconSize.x - 1, iconSize.y - 1); >+ } >+ } >+ if (showSelection && isSelect() && enabled) { >+ Color HIGHLIGHT_SHADOW = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); >+ Color LIGHT_SHADOW = display.getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW); >+ Color SELECTION = display.getSystemColor(SWT.COLOR_LIST_SELECTION); >+ e.gc.setBackground(HIGHLIGHT_SHADOW); >+ e.gc.fillRectangle(0, 0, iconSize.x, iconSize.y); >+ e.gc.setForeground(NORMAL_SHADOW); >+ e.gc.drawLine(S, S, iconSize.x - S - 1, S); >+ e.gc.drawLine(S + 1, S + 1, iconSize.x - S - 2, S + 1); >+ e.gc.drawLine(S, S, S, iconSize.y - S - 1); >+ e.gc.drawLine(S + 1, S + 1, S + 1, iconSize.y - S - 2); >+ e.gc.setForeground(HIGHLIGHT_SHADOW); >+ e.gc.drawLine(iconSize.x - S - 1, S + 1, iconSize.x - S - 1, iconSize.y - S - 1); >+ e.gc.drawLine(S, iconSize.y - S - 1, iconSize.x - S - 1, iconSize.y - S - 1); >+ e.gc.setForeground(LIGHT_SHADOW); >+ e.gc.drawLine(iconSize.x - S - 2, S + 2, iconSize.x - S - 2, iconSize.y - S - 2); >+ e.gc.drawLine(S + 1, iconSize.x - S - 2, iconSize.x - S - 2, iconSize.y - S - 2); >+ e.gc.setForeground(SELECTION); >+ e.gc.drawRectangle(0, 0, iconSize.x - 1, iconSize.y - 1); >+ } >+ >+ if (getEnabled()) { >+ e.gc.drawImage(image, S + B, S + B); >+ } else { >+ Image disabled = new Image(display, image, SWT.IMAGE_DISABLE); >+ e.gc.drawImage(disabled, S + B, S + B); >+ } >+ >+ if (bMenu) { >+ if (Platform.getWS().equalsIgnoreCase(Platform.WS_WIN32) >+ || Platform.getWS().equalsIgnoreCase(Platform.WS_WPF)) { >+ Color FOREGROUND = display.getSystemColor((getEnabled()) ? SWT.COLOR_WIDGET_FOREGROUND >+ : SWT.COLOR_WIDGET_DARK_SHADOW); >+ e.gc.setForeground(FOREGROUND); >+ int x = iconSize.x + G; >+ int y = S + B + M; >+ int h = 6; >+ while (h >= 0) { >+ e.gc.drawLine(x, y, x, y + h); >+ x++; >+ y++; >+ h -= 2; >+ } >+ } else { >+ Color FOREGROUND = display.getSystemColor((getEnabled()) ? SWT.COLOR_WIDGET_DARK_SHADOW >+ : SWT.COLOR_WIDGET_NORMAL_SHADOW); >+ e.gc.setForeground(FOREGROUND); >+ int x = iconSize.x + G; >+ int y = S + B + M; >+ int h = 4; >+ e.gc.drawLine(x, y, x + h / 2 + 1, y + h / 2 + 1); >+ e.gc.drawLine(x, y + 1, x + h / 2, y + h / 2 + 1); >+ e.gc.drawLine(x, y + h + 1, x + h / 2, y + h / 2 + 1); >+ e.gc.drawLine(x, y + h + 2, x + h / 2, y + h / 2 + 2); >+ } >+ } >+ e.gc.setBackground(background); >+ e.gc.setForeground(foreground); >+ //System.out.println(e.toString()); >+ } >+ }); >+ >+ addMouseListener(new MouseAdapter() { >+ @Override >+ public void mouseDown(MouseEvent e) { >+ if (e.x < iconSize.x && e.y < iconSize.y) { >+ if (showSelection) { >+ clickBody(); >+ return; >+ } else { >+ invokeMenu((Composite) e.widget); >+ } >+ } else { >+ invokeMenu((Composite) e.widget); >+ } >+ } >+ >+ private void invokeMenu(Composite widget) { >+ Rectangle b = widget.getBounds(); >+ Point p = widget.getLocation(); >+ p.x += b.width + 3; >+ bMouse = false; >+ redraw(); >+ clickMenu(p.x, p.y); >+ } >+ }); >+ >+ addListener(SWT.MouseEnter, new Listener() { >+ >+ public void handleEvent(Event event) { >+ if (getEnabled()) { >+ bMouse = true; >+ redraw(); >+ } >+ } >+ }); >+ addListener(SWT.MouseMove, new Listener() { >+ >+ public void handleEvent(Event event) { >+ if (getEnabled()) { >+ bMouse = true; >+ redraw(); >+ } >+ } >+ }); >+ addListener(SWT.MouseExit, new Listener() { >+ >+ public void handleEvent(Event event) { >+ if (getEnabled()) { >+ bMouse = false; >+ redraw(); >+ } >+ } >+ }); >+ } >+ >+ @Override >+ public Point computeSize(int wHint, int hHint, boolean changed) { >+ if (!getVisible()) { >+ return new Point(0, 0); >+ } >+ return maxSize; >+ } >+ >+ public void setImage(Image image) { >+ this.image = image; >+ } >+ >+ public void clickBody() { >+ } >+ >+ public void clickMenu(int x, int y) { >+ } >+ >+ public boolean isSelect() { >+ return false; >+ } >+ } >+ >+ private ToolActionItem[] items; >+ >+ private int selectedItemID; >+ >+ private ToolComposite toolButton; >+ >+ private Menu dropDownMenu; >+ >+ private int intgerCustom; >+ >+ private String stringCustom; >+ >+ private boolean showMenuAlways; >+ >+ public boolean isShowMenuAlways() { >+ return showMenuAlways; >+ } >+ >+ public void setShowMenuAlways(boolean showMenuAlways) { >+ this.showMenuAlways = showMenuAlways; >+ } >+ >+ @Override >+ public void runWithEvent(Event event) { >+ if (showMenuAlways) { >+ IMenuCreator mc = getMenuCreator(); >+ if (mc != null) { >+ Widget item = event.widget; >+ ToolItem ti = (ToolItem) item; >+ Menu m = mc.getMenu(ti.getParent()); >+ if (m != null) { >+ // position the menu below the drop down item >+ Rectangle itemBounds = ti.getBounds(); >+ Point point = ti.getParent().toDisplay(itemBounds.x, itemBounds.y + itemBounds.height); >+ m.setLocation(point.x, point.y); // waiting for SWT >+ m.setVisible(true); >+ return; // we don't fire the action >+ } >+ } >+ } >+ super.runWithEvent(event); >+ } >+ >+ public static final int ZOOM_FIT = 0; >+ >+ public static final int DRAW_FREE = 0; >+ >+ public static final int DRAW_LINE = 1; >+ >+ public static final int DRAW_ARROW1 = 2; >+ >+ public static final int DRAW_ARROW2 = 3; >+ >+ public static final int DRAW_BOX = 10; >+ >+ public static final int DRAW_RBOX = 11; >+ >+ public static final int DRAW_FILL_BOX = 12; >+ >+ public static final int DRAW_FILL_RBOX = 13; >+ >+ public static final int DRAW_OVAL = 20; >+ >+ public static final int DRAW_FILL_OVAL = 21; >+ >+ public static final int DRAW_TEXT = 30; >+ >+ public static final int CAPTURE_DESKTOP = 0; >+ >+ public static final int CAPTURE_CLIPBOARD = 1; >+ >+ public static final int CAPTURE_FILE = 2; >+ >+ public static final int CAPTURE_RECTANGLE = 3; >+ >+ public int getSelect() { >+ return selectedItemID; >+ } >+ >+ public void setUnselect() { >+ selectedItemID = -1; >+ if (toolButton != null) { >+ if (getId().equals(DRAWTEXT_TOOLBAR + "")) { //$NON-NLS-1$ >+ FontData fontData = new FontData(stringCustom); >+ toolButton.setImage(createFontImage(fontData, int2rgb(intgerCustom), false)); >+ } >+ toolButton.redraw(); >+ } >+ } >+ >+ public int getIntgerCustom() { >+ return intgerCustom; >+ } >+ >+ public String getStringCustom() { >+ return stringCustom; >+ } >+ >+ protected void selectItem(String label, ImageDescriptor image) { >+ for (ToolActionItem actionItem : items) { >+ if (actionItem.label.equals(label)) { >+ selectedItemID = actionItem.id; >+ if (getId().equals(CAPTURE_DROP_DOWN_MENU + "")) { //$NON-NLS-1$ >+ if (selectedItemID == CAPTURE_FILE) { >+ FileDialog dialog = new FileDialog(parent.getShell()); >+ dialog.setFileName(filename); >+ dialog.setFilterExtensions(new String[] { "*.bmp;*.jpg;*.png", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ >+ String result = dialog.open(); >+ if (result != null && result.length() > 0) { >+ filename = result; >+ run(); >+ } >+ } else { >+ run(); >+ } >+ selectedItemID = CAPTURE_DESKTOP; >+ } else { >+ setToolTipText(label); >+ if (image != null) { >+ setImageDescriptor(image); >+ } >+ if (toolButton != null) { >+ toolButton.setToolTipText(label); >+ if (image != null) { >+ toolButton.setImage(image.createImage()); >+ } >+ toolButton.redraw(); >+ } >+ run(); >+ } >+ break; >+ } >+ } >+ } >+ >+ private void addActionsToMenu() { >+ for (ToolActionItem actionItem : items) { >+ Action action = new Action() { >+ @Override >+ public void run() { >+ selectItem(getText(), getImageDescriptor()); >+ } >+ }; >+ action.setText(actionItem.label); >+ if (actionItem.image != null) { >+ action.setImageDescriptor(actionItem.image); >+ } >+ updateAction(action, actionItem.id); >+ ActionContributionItem contributionItem = new ActionContributionItem(action); >+ contributionItem.fill(dropDownMenu, -1); >+ } >+ } >+ >+ private void updateAction(Action action, int id) { >+ action.setChecked(id == selectedItemID); >+ if (getId().equals(CAPTURE_DROP_DOWN_MENU + "")) { //$NON-NLS-1$ >+ if (id == CAPTURE_CLIPBOARD) { >+ action.setEnabled(existImageOnClipboard()); >+ } else if (id == CAPTURE_RECTANGLE) { >+ action.setEnabled(isEnableRectangle()); >+ } >+ } >+ } >+ >+ protected boolean isEnableRectangle() { >+ return false; >+ } >+ >+ public void dispose() { >+ if (toolButton != null) { >+ toolButton.dispose(); >+ toolButton = null; >+ } >+ if (dropDownMenu != null) { >+ dropDownMenu.dispose(); >+ dropDownMenu = null; >+ } >+ } >+ >+ public Menu getMenu(Control parent) { >+ if (dropDownMenu != null) { >+ dropDownMenu.dispose(); >+ } >+ dropDownMenu = new Menu(parent); >+ addActionsToMenu(); >+ return dropDownMenu; >+ } >+ >+ public Menu getMenu(Menu parent) { >+ if (dropDownMenu != null) { >+ dropDownMenu.dispose(); >+ } >+ dropDownMenu = new Menu(parent); >+ addActionsToMenu(); >+ return dropDownMenu; >+ } >+ >+ private final Composite parent; >+ >+ private boolean showSelection; >+ >+ private String filename; >+ >+ public boolean getVisible() { >+ if (toolButton != null) { >+ return toolButton.getVisible(); >+ } >+ return false; >+ } >+ >+ public void setVisible(boolean visible) { >+ if (toolButton != null) { >+ toolButton.setVisible(visible); >+ toolButton.redraw(); >+ } >+ } >+ >+ public boolean getEnabled() { >+ if (toolButton != null) { >+ return toolButton.getEnabled(); >+ } >+ return false; >+ } >+ >+ @Override >+ public void setEnabled(boolean enabled) { >+ super.setEnabled(enabled); >+ if (toolButton != null) { >+ toolButton.setEnabled(enabled); >+ toolButton.redraw(); >+ } >+ } >+ >+ public Image getFileImage() { >+ try { >+ Image image = new Image(parent.getShell().getDisplay(), filename); >+ return image; >+ } catch (Exception e) { >+ // None >+ } >+ return null; >+ } >+ >+ public Image getClipboardImage() { >+ try { >+ Clipboard clipboard = new Clipboard(parent.getShell().getDisplay()); >+ ImageTransfer imageTransfer = ImageTransfer.getInstance(); >+ Object data = clipboard.getContents(imageTransfer); >+ if (data instanceof ImageData) { >+ Image image = new Image(parent.getShell().getDisplay(), (ImageData) data); >+ return image; >+ } >+ } catch (Exception e) { >+ // None >+ } >+ return null; >+ } >+ >+ private boolean existImageOnClipboard() { >+ try { >+ Clipboard clipboard = new Clipboard(parent.getShell().getDisplay()); >+ ImageTransfer imageTransfer = ImageTransfer.getInstance(); >+ Object data = clipboard.getContents(imageTransfer); >+ if (data instanceof ImageData) { >+ return true; >+ } >+ } catch (Exception e) { >+ // None >+ } >+ return false; >+ } >+ >+ public static int rgb2int(RGB rgb) { >+ return rgb2int(rgb.red, rgb.green, rgb.blue); >+ } >+ >+ public static int rgb2int(int r, int g, int b) { >+ return (r << 16) + (g << 8) + b; >+ } >+ >+ public static RGB int2rgb(int rgb) { >+ return new RGB(rgb >> 16, (rgb >> 8) & 0x00ff, rgb & 0x00ff); >+ } >+ >+ private String font2string(FontData fontData) { >+ String info = NLS.bind(Messages.SelectToolAction_Font_Name_Size, // >+ new Object[] { fontData.getName(), fontData.getHeight() + "" }); //$NON-NLS-1$ >+ int style = fontData.getStyle(); >+ if ((style & SWT.BOLD) != 0) { >+ info = info + Messages.SelectToolAction_Font_Bold; >+ } >+ if ((style & SWT.ITALIC) != 0) { >+ info = info + Messages.SelectToolAction_Font_Italic; >+ } >+ return info; >+ } >+}
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 266123
:
126712
|
126835
|
126836
|
127074
|
127102
|
127103
|
127110
|
127892
|
127914
|
127915
|
128171
|
134062
|
134063
|
134067
|
134078
|
134195
|
134984
| 135048 |
135049