org.eclipse.mylyn.commons.screenshots_3.7.1.v20120425-0100

16:46:30.810 INFO  jd.cli.Main - Decompiling org.eclipse.mylyn.commons.screenshots_3.7.1.v20120425-0100.jar
package org.eclipse.mylyn.commons.ui.screenshots;

import java.util.ArrayList;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Canvas;

class ScreenshotViewer$6
  extends Action
{
  ScreenshotViewer$6(ScreenshotViewer paramScreenshotViewer, String $anonymous0, int $anonymous1)
  {
    super($anonymous0, $anonymous1);
  }
  
  public void run()
  {
    ScreenshotViewer.access$22(this$0).setEnabled(false);
    ScreenshotViewer.access$36(this$0).drawImage(ScreenshotViewer.access$37(this$0), 0, 0);
    ScreenshotViewer.access$26(this$0).redraw();
    this$0.setDirty(true);
    
    ScreenshotViewer.access$15(this$0, new ArrayList());
    ScreenshotViewer.access$16(this$0, new ArrayList());
    ScreenshotViewer.access$17(this$0, new ArrayList());
    ScreenshotViewer.access$18(this$0, new ArrayList());
    ScreenshotViewer.access$19(this$0, 0);
    ScreenshotViewer.access$20(this$0).setEnabled(false);
    ScreenshotViewer.access$21(this$0).setEnabled(false);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.ui.screenshots.ScreenshotViewer.6
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.ui.screenshots;

import org.eclipse.mylyn.internal.commons.ui.screenshots.Messages;
import org.eclipse.mylyn.internal.commons.ui.screenshots.SelectToolAction;
import org.eclipse.swt.events.MenuDetectEvent;
import org.eclipse.swt.events.MenuDetectListener;
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;

class ScreenshotViewer$12
  implements MenuDetectListener
{
  ScreenshotViewer$12(ScreenshotViewer paramScreenshotViewer) {}
  
  public void menuDetected(MenuDetectEvent e)
  {
    Menu rightClickMenu = new Menu(Display.getDefault().getActiveShell(), 8);
    MenuItem menuItem = new MenuItem(rightClickMenu, 32);
    menuItem.setText(Messages.ScreenshotCreationPage_Show_Line_Type_Selector);
    menuItem.setSelection(ScreenshotViewer.access$34(this$0).getVisible());
    menuItem.addListener(13, new Listener()
    {
      public void handleEvent(Event event)
      {
        ScreenshotViewer.access$34(this$0).setVisible(!ScreenshotViewer.access$34(this$0).getVisible());
        ScreenshotViewer.access$27(this$0).layout();
      }
    });
    menuItem = new MenuItem(rightClickMenu, 32);
    menuItem.setText(Messages.ScreenshotCreationPage_Show_Line_Bold_Selector);
    menuItem.setSelection(ScreenshotViewer.access$35(this$0).getVisible());
    menuItem.addListener(13, new Listener()
    {
      public void handleEvent(Event event)
      {
        ScreenshotViewer.access$35(this$0).setVisible(!ScreenshotViewer.access$35(this$0).getVisible());
        ScreenshotViewer.access$27(this$0).layout();
      }
    });
    rightClickMenu.setLocation(x, y);
    rightClickMenu.setVisible(true);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.mylyn.commons.ui.screenshots.ScreenshotViewer.12
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.mylyn.commons.ui.screenshots;

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;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.mylyn.internal.commons.ui.screenshots.Messages;
import org.eclipse.mylyn.internal.commons.ui.screenshots.ScreenshotImages;
import org.eclipse.mylyn.internal.commons.ui.screenshots.SelectToolAction;
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.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
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;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Device;
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.Control;
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.ScrollBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.Widget;

public class ScreenshotViewer
{
  private SelectToolAction captureAction;
  private SelectToolAction fitAction;
  private IAction cropAction;
  private IAction markAction;
  private IAction clearAction;
  private IAction undoAction;
  private IAction redoAction;
  private Composite paletteArea;
  private int lastDrawAction;
  private IDialogSettings dialogSettings;
  private SelectToolAction drawLineToolbar;
  private SelectToolAction drawArrowToolbar;
  private SelectToolAction drawBoxToolbar;
  private SelectToolAction drawTextToolbar;
  private SelectToolAction lineTypeToolbar;
  private SelectToolAction lineBoldToolbar;
  private SelectToolAction drawColorToolbar;
  private boolean dirty;
  private Image originalImage;
  private Image workImage;
  private Image previousImage;
  private GC workImageGC;
  private Canvas canvas;
  private ScrolledComposite scrolledComposite;
  private Rectangle currentSelection;
  private Rectangle originalSelection;
  private Point startPoint;
  private Set<SelectionSide> resizableSides = EnumSet.noneOf(SelectionSide.class);
  private double scaleFactor = 1.0D;
  private final Map<Integer, Cursor> cursors = new HashMap();
  
  private static enum EditorAction
  {
    CROPPING,  SELECTING,  RESIZING_SELECTION,  MOVING_SELECTION,  MARKING;
  }
  
  private EditorAction currentAction = EditorAction.CROPPING;
  private boolean isFirstCapture = true;
  private Text textArea;
  private List<int[]> historyMouseEvent = new ArrayList();
  private List<int[]> historyDrawTool = new ArrayList();
  private List<StringBuffer> historyDrawText = new ArrayList();
  private List<String> historyDrawFont = new ArrayList();
  private int historyCheckpoint = 0;
  private ViewForm vf;
  private static final int CURSOR_MARK_TOOL = -1;
  private static final int INITIAL_CAPTURE_DELAY = 400;
  private static final String DEFAULT_DELAY = "2";
  private static final String DELAY_DIALOG_KEY = "ScreenshotViewerDelayDialog";
  private static final String DELAY_DIALOG_DELAY_VALUE = "DelayValue";
  
  public ScreenshotViewer(Composite parent, int style)
  {
    createControl(parent, style);
  }
  
  public Control getControl()
  {
    return vf;
  }
  
  private void doDispose()
  {
    disposeImageResources();
    
    canvas.setCursor(null);
    for (Cursor cursor : cursors.values()) {
      cursor.dispose();
    }
  }
  
  private void createControl(Composite parent, int style)
  {
    vf = new ViewForm(parent, style);
    vf.horizontalSpacing = 0;
    vf.verticalSpacing = 0;
    vf.setLayoutData(GridDataFactory.fillDefaults().create());
    vf.addDisposeListener(new DisposeListener()
    {
      public void widgetDisposed(DisposeEvent e)
      {
        ScreenshotViewer.this.doDispose();
      }
    });
    allocateCursors();
    
    ToolBarManager tbm = new ToolBarManager(8519936);
    captureAction = new SelectToolAction(getShell(), Messages.ScreenshotCreationPage_Capture_Desktop_C, 
      1)
      {
        public void run()
        {
          if (captureAction.getSelect() == 0) {
            ScreenshotViewer.this.captureScreenshotContent(400);
          } else if (captureAction.getSelect() == 4) {
            ScreenshotViewer.this.captureScreenshotContentDelayed();
          } else if (captureAction.getSelect() == 1) {
            ScreenshotViewer.this.captureScreenshotContent(captureAction.getClipboardImage());
          } else if (captureAction.getSelect() == 3) {
            ScreenshotViewer.this.captureScreenshotContentFromSelection();
          } else {
            ScreenshotViewer.this.captureScreenshotContent(captureAction.getFileImage());
          }
          if (isFirstCapture)
          {
            isFirstCapture = false;
            fitAction.setEnabled(true);
            cropAction.setEnabled(true);
            cropAction.setChecked(true);
            markAction.setEnabled(true);
            drawLineToolbar.setEnabled(true);
            drawArrowToolbar.setEnabled(true);
            drawBoxToolbar.setEnabled(true);
            drawTextToolbar.setEnabled(true);
          }
          historyMouseEvent = new ArrayList();
          historyDrawTool = new ArrayList();
          historyDrawText = new ArrayList();
          historyDrawFont = new ArrayList();
          historyCheckpoint = 0;
          undoAction.setEnabled(false);
          redoAction.setEnabled(false);
          clearAction.setEnabled(false);
        }
        
        protected boolean isEnableRectangle()
        {
          return currentSelection != null;
        }
      };
      captureAction.setToolTipText(Messages.ScreenshotCreationPage_Capture_Desktop);
      captureAction.setImageDescriptor(ScreenshotImages.IMAGE_CAPTURE);
      captureAction.setShowMenuAlways(false);
      
      fitAction = new SelectToolAction(Messages.ScreenshotCreationPage_Fit_Image_F, 
        2)
        {
          public void run()
          {
            ScreenshotViewer.this.refreshCanvasSize();
          }
        };
        fitAction.setToolTipText(Messages.ScreenshotCreationPage_Fit_Image);
        fitAction.setImageDescriptor(ScreenshotImages.IMAGE_FIT);
        
        fitAction.setEnabled(false);
        
        cropAction = new Action(Messages.ScreenshotCreationPage_Crop_R, 8)
        {
          public void run()
          {
            currentAction = ScreenshotViewer.EditorAction.CROPPING;
            cropAction.setChecked(true);
            markAction.setChecked(false);
            
            canvas.redraw();
          }
        };
        cropAction.setToolTipText(Messages.ScreenshotCreationPage_Crop);
        cropAction.setImageDescriptor(ScreenshotImages.CUT);
        cropAction.setEnabled(false);
        
        markAction = new Action(Messages.ScreenshotCreationPage_Annotate, 8)
        {
          public void setChecked(boolean checked)
          {
            super.setChecked(checked);
            if (paletteArea != null)
            {
              if (checked)
              {
                if (ScreenshotViewer.this.getSelectDrawToolbar() < 0) {
                  ScreenshotViewer.this.setSelectDrawToolbar(lastDrawAction);
                }
              }
              else
              {
                int select = ScreenshotViewer.this.getSelectDrawToolbar();
                if (select >= 0)
                {
                  lastDrawAction = select;
                  ScreenshotViewer.this.unselectDrawToolbar();
                }
              }
              boolean isDrawText = drawTextToolbar.getSelect() >= 0 ? false : checked;
              
              drawColorToolbar.setEnabled(isDrawText);
              lineTypeToolbar.setEnabled(isDrawText);
              lineBoldToolbar.setEnabled(isDrawText);
            }
          }
          
          public void run()
          {
            currentAction = ScreenshotViewer.EditorAction.MARKING;
            cropAction.setChecked(false);
            markAction.setChecked(true);
            
            canvas.redraw();
          }
        };
        markAction.setToolTipText(Messages.ScreenshotCreationPage_DRAW_ANNOTATION_ON_SCREENSHOT_IMAGE);
        markAction.setImageDescriptor(ScreenshotImages.EDIT);
        
        markAction.setEnabled(false);
        
        clearAction = new Action(Messages.ScreenshotCreationPage_Clear, 1)
        {
          public void run()
          {
            clearAction.setEnabled(false);
            workImageGC.drawImage(originalImage, 0, 0);
            canvas.redraw();
            setDirty(true);
            
            historyMouseEvent = new ArrayList();
            historyDrawTool = new ArrayList();
            historyDrawText = new ArrayList();
            historyDrawFont = new ArrayList();
            historyCheckpoint = 0;
            undoAction.setEnabled(false);
            redoAction.setEnabled(false);
          }
        };
        clearAction.setToolTipText(Messages.ScreenshotCreationPage_Clear_all_annotations_made_on_screenshot_image);
        clearAction.setImageDescriptor(ScreenshotImages.CLEAR);
        clearAction.setEnabled(false);
        
        undoAction = new Action(Messages.ScreenshotCreationPage_Undo)
        {
          public void run()
          {
            if (historyCheckpoint > 0)
            {
              historyCheckpoint -= 1;
              ScreenshotViewer.this.drawAnnotationHistory();
            }
            if (historyCheckpoint == 0) {
              undoAction.setEnabled(false);
            }
            if (historyCheckpoint < historyDrawTool.size()) {
              redoAction.setEnabled(true);
            }
          }
        };
        undoAction.setToolTipText(Messages.ScreenshotCreationPage_Undo_annotation);
        undoAction.setImageDescriptor(ScreenshotImages.UNDO);
        undoAction.setEnabled(false);
        
        redoAction = new Action(Messages.ScreenshotCreationPage_Redo)
        {
          public void run()
          {
            if (historyCheckpoint < historyDrawTool.size())
            {
              historyCheckpoint += 1;
              ScreenshotViewer.this.drawAnnotationHistory();
            }
            if (historyCheckpoint > 0) {
              undoAction.setEnabled(true);
            }
            if (historyCheckpoint >= historyDrawTool.size()) {
              redoAction.setEnabled(false);
            }
          }
        };
        redoAction.setToolTipText(Messages.ScreenshotCreationPage_Redo_annotation);
        redoAction.setImageDescriptor(ScreenshotImages.REDO);
        redoAction.setEnabled(false);
        
        tbm.add(createAndConfigureCI(captureAction));
        tbm.add(new Separator());
        tbm.add(createAndConfigureCI(fitAction));
        tbm.add(createAndConfigureCI(cropAction));
        tbm.add(createAndConfigureCI(markAction));
        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, 0);
        GridLayout layout = new GridLayout(2, false);
        horizontalSpacing = 0;
        verticalSpacing = 0;
        marginWidth = 0;
        marginHeight = 0;
        body.setLayout(layout);
        createPaletteBars(body);
        lastDrawAction = getSelectDrawToolbar();
        unselectDrawToolbar();
        
        scrolledComposite = new ScrolledComposite(body, 768);
        scrolledComposite.setLayoutData(new GridData(1808));
        canvas = new Canvas(scrolledComposite, 536870912);
        scrolledComposite.setContent(canvas);
        canvas.addPaintListener(new PaintListener()
        {
          public void paintControl(PaintEvent e)
          {
            if (workImage != null)
            {
              Rectangle imageBounds = workImage.getBounds();
              Rectangle canvasBounds = canvas.getClientArea();
              
              int zoom = fitAction.getSelect();
              switch (zoom)
              {
              case 0: 
                gc.drawImage(workImage, 0, 0, width, height, 
                  0, 0, width, height);
                break;
              case 50: 
                gc.drawImage(workImage, 0, 0, width, height, 
                  0, 0, width / 2, height / 2);
                break;
              case 100: 
                gc.drawImage(workImage, 0, 0);
                break;
              default: 
                gc.drawImage(workImage, 0, 0, width, height, 
                  0, 0, width * zoom / 100, height * zoom / 100);
              }
              ScreenshotViewer.this.drawSelection(gc);
            }
            else
            {
              fitAction.setEnabled(false);
            }
          }
        });
        scrolledComposite.addControlListener(new ControlAdapter()
        {
          public void controlResized(ControlEvent e)
          {
            if (fitAction.getSelect() == 0) {
              ScreenshotViewer.this.refreshCanvasSize();
            }
          }
        });
        scrolledComposite.setEnabled(false);
        
        ToolBar control = tbm.createControl(vf);
        vf.setTopLeft(control);
        vf.setContent(body);
        registerMouseListeners();
        
        vf.setLayoutData(new GridData(1808));
        
        Dialog.applyDialogFont(vf);
      }
      
      private Shell getShell()
      {
        return getControl().getShell();
      }
      
      private void createPaletteBars(Composite body)
      {
        paletteArea = new Composite(body, 0);
        paletteArea.setLayoutData(new GridData(1040));
        RowLayout rowlayout = new RowLayout(512);
        marginRight += 1;
        paletteArea.setLayout(rowlayout);
        
        paletteArea.addListener(9, new Listener()
        {
          public void handleEvent(Event e)
          {
            Color gcForeground = gc.getForeground();
            Rectangle bounds = ((Composite)widget).getBounds();
            Color border = widget.getDisplay().getSystemColor(18);
            gc.setForeground(border);
            gc.drawLine(width - 1, 0, width - 1, height);
            gc.setForeground(gcForeground);
          }
        });
        paletteArea.addMenuDetectListener(new MenuDetectListener()
        {
          public void menuDetected(MenuDetectEvent e)
          {
            Menu rightClickMenu = new Menu(Display.getDefault().getActiveShell(), 8);
            MenuItem menuItem = new MenuItem(rightClickMenu, 32);
            menuItem.setText(Messages.ScreenshotCreationPage_Show_Line_Type_Selector);
            menuItem.setSelection(lineTypeToolbar.getVisible());
            menuItem.addListener(13, new Listener()
            {
              public void handleEvent(Event event)
              {
                lineTypeToolbar.setVisible(!lineTypeToolbar.getVisible());
                paletteArea.layout();
              }
            });
            menuItem = new MenuItem(rightClickMenu, 32);
            menuItem.setText(Messages.ScreenshotCreationPage_Show_Line_Bold_Selector);
            menuItem.setSelection(lineBoldToolbar.getVisible());
            menuItem.addListener(13, new Listener()
            {
              public void handleEvent(Event event)
              {
                lineBoldToolbar.setVisible(!lineBoldToolbar.getVisible());
                paletteArea.layout();
              }
            });
            rightClickMenu.setLocation(x, y);
            rightClickMenu.setVisible(true);
          }
        });
        drawLineToolbar = new SelectToolAction(paletteArea, 3)
        {
          public void run()
          {
            markAction.run();
            drawArrowToolbar.setUnselect();
            drawBoxToolbar.setUnselect();
            drawTextToolbar.setUnselect();
            drawColorToolbar.setEnabled(true);
            lineTypeToolbar.setEnabled(true);
            lineBoldToolbar.setEnabled(true);
          }
        };
        drawLineToolbar.setEnabled(false);
        drawArrowToolbar = new SelectToolAction(paletteArea, 4)
        {
          public void run()
          {
            markAction.run();
            drawLineToolbar.setUnselect();
            drawBoxToolbar.setUnselect();
            drawTextToolbar.setUnselect();
            drawColorToolbar.setEnabled(true);
            lineTypeToolbar.setEnabled(true);
            lineBoldToolbar.setEnabled(true);
          }
        };
        drawArrowToolbar.setEnabled(false);
        drawBoxToolbar = new SelectToolAction(paletteArea, 5)
        {
          public void run()
          {
            markAction.run();
            drawLineToolbar.setUnselect();
            drawArrowToolbar.setUnselect();
            drawTextToolbar.setUnselect();
            drawColorToolbar.setEnabled(true);
            lineTypeToolbar.setEnabled(true);
            lineBoldToolbar.setEnabled(true);
          }
        };
        drawBoxToolbar.setEnabled(false);
        drawTextToolbar = new SelectToolAction(paletteArea, 6)
        {
          public void run()
          {
            markAction.run();
            drawLineToolbar.setUnselect();
            drawArrowToolbar.setUnselect();
            drawBoxToolbar.setUnselect();
            drawColorToolbar.setEnabled(false);
            lineTypeToolbar.setEnabled(false);
            lineBoldToolbar.setEnabled(false);
          }
        };
        drawTextToolbar.setEnabled(false);
        drawColorToolbar = new SelectToolAction(paletteArea, 9);
        drawColorToolbar.setEnabled(false);
        lineTypeToolbar = new SelectToolAction(paletteArea, 7);
        lineTypeToolbar.setEnabled(false);
        lineTypeToolbar.setVisible(false);
        lineBoldToolbar = new SelectToolAction(paletteArea, 8);
        lineBoldToolbar.setEnabled(false);
        lineBoldToolbar.setVisible(false);
      }
      
      private void setSelectDrawToolbar(int drawTool)
      {
        if (drawLineToolbar.setSelect(drawTool))
        {
          drawArrowToolbar.setUnselect();
          drawBoxToolbar.setUnselect();
          drawTextToolbar.setUnselect();
          return;
        }
        if (drawArrowToolbar.setSelect(drawTool))
        {
          drawLineToolbar.setUnselect();
          drawBoxToolbar.setUnselect();
          drawTextToolbar.setUnselect();
          return;
        }
        if (drawBoxToolbar.setSelect(drawTool))
        {
          drawLineToolbar.setUnselect();
          drawArrowToolbar.setUnselect();
          drawTextToolbar.setUnselect();
          return;
        }
        drawLineToolbar.setUnselect();
        drawArrowToolbar.setUnselect();
        drawBoxToolbar.setUnselect();
        drawTextToolbar.setSelect(drawTool);
      }
      
      private void unselectDrawToolbar()
      {
        drawLineToolbar.setUnselect();
        drawArrowToolbar.setUnselect();
        drawBoxToolbar.setUnselect();
        drawTextToolbar.setUnselect();
      }
      
      private int getSelectDrawToolbar()
      {
        int drawTool;
        if ((drawTool = drawLineToolbar.getSelect()) >= 0) {
          return drawTool;
        }
        if ((drawTool = drawArrowToolbar.getSelect()) >= 0) {
          return drawTool;
        }
        if ((drawTool = drawBoxToolbar.getSelect()) >= 0) {
          return drawTool;
        }
        if ((drawTool = drawTextToolbar.getSelect()) >= 0) {
          return drawTool;
        }
        return -1;
      }
      
      private ActionContributionItem createAndConfigureCI(IAction action)
      {
        ActionContributionItem ci = new ActionContributionItem(action);
        ci.setMode(ActionContributionItem.MODE_FORCE_TEXT);
        return ci;
      }
      
      private void disposeImageResources()
      {
        if (originalImage != null) {
          originalImage.dispose();
        }
        if (workImageGC != null) {
          workImageGC.dispose();
        }
        if (workImage != null) {
          workImage.dispose();
        }
      }
      
      private void allocateCursors()
      {
        Display display = getShell().getDisplay();
        cursors.put(Integer.valueOf(0), new Cursor(display, 0));
        cursors.put(Integer.valueOf(5), new Cursor(display, 5));
        cursors.put(Integer.valueOf(8), new Cursor(display, 8));
        cursors.put(Integer.valueOf(6), new Cursor(display, 6));
        cursors.put(Integer.valueOf(7), new Cursor(display, 7));
        cursors.put(Integer.valueOf(9), new Cursor(display, 9));
        cursors.put(Integer.valueOf(2), new Cursor(display, 2));
        
        cursors.put(Integer.valueOf(-1), new Cursor(display, 21));
      }
      
      private Rectangle getScaledSelection()
      {
        if (currentSelection == null) {
          return null;
        }
        int x = (int)Math.round(currentSelection.x * scaleFactor);
        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 * 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(x - 6, y - 6, 
          width + 12 + 1, height + 12 + 1);
      }
      
      private static final int[][] grapGroupPoints = {
        new int[3], { 1 }, { 2, 0, 1 }, { 3, 0, 2 }, { 4, 0, 2 }, 
        { 0, 1 }, { 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 = { x, 
          x, 
          x + 12, 
          x + width - 12, 
          x + width, 
          x + width };
        int[] yGroupPoint = { y, 
          y, 
          y + 12, 
          y + height - 12, 
          y + height, 
          y + height };
        int xGroup = -1;int yGroup = -1;
        Object localObject;
        int j = (localObject = grapScanOrder).length;
        for (int i = 0; i < j; i++)
        {
          int element = localObject[i];
          if ((xGroupPoint[element] <= x) && (x <= xGroupPoint[(element + 1)]))
          {
            xGroup = element;
            break;
          }
        }
        if (xGroup < 0) {
          return -1;
        }
        j = (localObject = grapScanOrder).length;
        for (i = 0; i < j; i++)
        {
          int element = localObject[i];
          if ((yGroupPoint[element] <= y) && (y <= yGroupPoint[(element + 1)]))
          {
            yGroup = element;
            break;
          }
        }
        if (yGroup < 0) {
          return -1;
        }
        j = (localObject = grapGroupPoints).length;
        for (i = 0; i < j; i++)
        {
          int[] element = localObject[i];
          if ((element[0] == xGroup) && (element[1] == yGroup)) {
            return element[2];
          }
        }
        return -1;
      }
      
      public boolean isComplete()
      {
        return workImage != null;
      }
      
      private void captureScreenshotContent(Image image)
      {
        Display display = getShell().getDisplay();
        disposeImageResources();
        originalImage = image;
        Rectangle displayBounds = originalImage.getBounds();
        workImage = new Image(display, width, height);
        GC gc = new GC(workImage);
        gc.drawImage(originalImage, 0, 0);
        gc.dispose();
        
        workImageGC = new GC(workImage);
        workImageGC.setLineCap(2);
        
        scrolledComposite.setEnabled(true);
        clearSelection();
        refreshCanvasSize();
        
        stateChanged();
      }
      
      protected void stateChanged() {}
      
      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, width, height);
        gc = new GC(workImage);
        gc.drawImage(originalImage, 0, 0);
        gc.dispose();
        
        workImageGC = new GC(workImage);
        workImageGC.setLineCap(2);
        
        scrolledComposite.setEnabled(true);
        clearSelection();
        refreshCanvasSize();
        
        stateChanged();
      }
      
      private void captureScreenshotContent(int delay)
      {
        final Display display = getShell().getDisplay();
        final Shell wizardShell = getShell();
        wizardShell.setVisible(false);
        
        getShell().getDisplay().timerExec(delay, new Runnable()
        {
          public void run()
          {
            ScreenshotViewer.this.disposeImageResources();
            Rectangle displayBounds = display.getBounds();
            originalImage = new Image(display, width, height);
            workImage = new Image(display, width, height);
            
            GC gc = new GC(display);
            gc.copyArea(originalImage, x, y);
            gc.copyArea(workImage, x, y);
            gc.dispose();
            
            workImageGC = new GC(workImage);
            workImageGC.setLineCap(2);
            
            scrolledComposite.setEnabled(true);
            ScreenshotViewer.this.clearSelection();
            ScreenshotViewer.this.refreshCanvasSize();
            
            wizardShell.setVisible(true);
            stateChanged();
          }
        });
      }
      
      private void captureScreenshotContentDelayed()
      {
        IInputValidator delayValidator = new IInputValidator()
        {
          public String isValid(String newText)
          {
            try
            {
              int result = Integer.parseInt(newText);
              if (result > 0) {
                return null;
              }
            }
            catch (NumberFormatException localNumberFormatException) {}
            return Messages.ScreenshotViewer_EnterValidSeconds;
          }
        };
        String delay = getDelayFromSettings("2");
        InputDialog delayDialog = new InputDialog(getShell(), Messages.ScreenshotViewer_Delay, 
          Messages.ScreenshotViewer_EnterDelayForScreenshot, delay, delayValidator);
        int resultCode = delayDialog.open();
        if (resultCode == 0)
        {
          storeDelaySetting(delayDialog.getValue());
          int newDelay = Integer.parseInt(delayDialog.getValue());
          int newDelayInMs = newDelay * 1000;
          captureScreenshotContent(400 + newDelayInMs);
        }
      }
      
      private void storeDelaySetting(String value)
      {
        if (dialogSettings != null)
        {
          IDialogSettings section = dialogSettings.getSection("ScreenshotViewerDelayDialog");
          if (section == null) {
            section = dialogSettings.addNewSection("ScreenshotViewerDelayDialog");
          }
          section.put("DelayValue", value);
        }
      }
      
      private String getDelayFromSettings(String defaultValue)
      {
        String delay = defaultValue;
        if (dialogSettings != null)
        {
          IDialogSettings section = dialogSettings.getSection("ScreenshotViewerDelayDialog");
          if (section != null)
          {
            int lastDelay = section.getInt("DelayValue");
            delay = String.valueOf(lastDelay);
          }
        }
        return delay;
      }
      
      public void setDialogSettings(IDialogSettings dialogSettings)
      {
        this.dialogSettings = dialogSettings;
      }
      
      public IDialogSettings getDialogSettings()
      {
        return dialogSettings;
      }
      
      private void refreshCurrentSelection(int x, int y)
      {
        int startX = Math.min(startPoint.x, x);
        int startY = Math.min(startPoint.y, y);
        int width = Math.abs(startPoint.x - x);
        int height = Math.abs(startPoint.y - y);
        currentSelection = new Rectangle(startX, startY, width, height);
        
        Rectangle imageBounds = workImage.getBounds();
        width -= 1;
        height -= 1;
        currentSelection.intersect(imageBounds);
      }
      
      private static final int[] grabPointCurosr = { 8, 7, 6, 
        9, 9, 6, 7, 8 };
      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 static final int SQUARE_SIZE = 3;
      
      private void refreshSelectionResize(int x, int y)
      {
        currentSelection = new Rectangle(originalSelection.x, originalSelection.y, originalSelection.width, 
          originalSelection.height);
        int deltaX = x - startPoint.x;
        int deltaY = y - startPoint.y;
        Rectangle imageBounds = workImage.getBounds();
        if (resizableSides.contains(SelectionSide.LEFT))
        {
          deltaX = Math.min(deltaX, originalSelection.width);
          if (originalSelection.x + deltaX < 0) {
            deltaX = -originalSelection.x;
          }
        }
        if (resizableSides.contains(SelectionSide.RIGHT))
        {
          deltaX = Math.max(deltaX, -originalSelection.width);
          if (originalSelection.x + originalSelection.width + deltaX > width) {
            deltaX = width - (originalSelection.x + originalSelection.width);
          }
        }
        if (resizableSides.contains(SelectionSide.TOP))
        {
          deltaY = Math.min(deltaY, originalSelection.height);
          if (originalSelection.y + deltaY < 0) {
            deltaY = -originalSelection.y;
          }
        }
        if (resizableSides.contains(SelectionSide.BOTTOM))
        {
          deltaY = Math.max(deltaY, -originalSelection.height);
          if (originalSelection.y + originalSelection.height + deltaY > height) {
            deltaY = height - (originalSelection.y + originalSelection.height);
          }
        }
        if (resizableSides.contains(SelectionSide.LEFT))
        {
          currentSelection.x += deltaX;
          currentSelection.width -= deltaX;
        }
        if (resizableSides.contains(SelectionSide.RIGHT)) {
          currentSelection.width += deltaX;
        }
        if (resizableSides.contains(SelectionSide.TOP))
        {
          currentSelection.y += deltaY;
          currentSelection.height -= deltaY;
        }
        if (resizableSides.contains(SelectionSide.BOTTOM)) {
          currentSelection.height += deltaY;
        }
      }
      
      private void refreshSelectionPosition(int x, int y)
      {
        int newX = originalSelection.x + (x - startPoint.x);
        int newY = originalSelection.y + (y - startPoint.y);
        if (newX < 0) {
          newX = 0;
        }
        if (newY < 0) {
          newY = 0;
        }
        Rectangle imageBounds = workImage.getBounds();
        if (newX + originalSelection.width > width) {
          newX = width - originalSelection.width;
        }
        if (newY + originalSelection.height > height) {
          newY = height - originalSelection.height;
        }
        currentSelection = new Rectangle(newX, newY, originalSelection.width, originalSelection.height);
      }
      
      private void registerMouseListeners()
      {
        canvas.addMouseMoveListener(new MouseMoveListener()
        {
          public void mouseMove(MouseEvent e)
          {
            int scaledX = (int)Math.round(x / scaleFactor);
            int scaledY = (int)Math.round(y / scaleFactor);
            if (currentAction == ScreenshotViewer.EditorAction.SELECTING)
            {
              ScreenshotViewer.this.refreshCurrentSelection(scaledX, scaledY);
              canvas.redraw();
            }
            else if (currentAction == ScreenshotViewer.EditorAction.RESIZING_SELECTION)
            {
              ScreenshotViewer.this.refreshSelectionResize(scaledX, scaledY);
              canvas.redraw();
            }
            else if (currentAction == ScreenshotViewer.EditorAction.MOVING_SELECTION)
            {
              ScreenshotViewer.this.refreshSelectionPosition(scaledX, scaledY);
              canvas.redraw();
            }
            else if ((currentAction == ScreenshotViewer.EditorAction.CROPPING) && (currentSelection != null))
            {
              boolean cursorSet = false;
              
              int info = ScreenshotViewer.this.getGrabPoint(x, y);
              if (info >= 0)
              {
                canvas.setCursor((Cursor)cursors.get(Integer.valueOf(ScreenshotViewer.grabPointCurosr[info])));
                cursorSet = true;
              }
              if ((!cursorSet) && (ScreenshotViewer.this.getScaledSelection().contains(x, y)))
              {
                canvas.setCursor((Cursor)cursors.get(Integer.valueOf(5)));
                cursorSet = true;
              }
              Cursor crossCursor = (Cursor)cursors.get(Integer.valueOf(2));
              if ((!cursorSet) && (canvas.getCursor() != crossCursor)) {
                canvas.setCursor(crossCursor);
              }
            }
            else if (currentAction == ScreenshotViewer.EditorAction.MARKING)
            {
              if (startPoint != null)
              {
                int drawTool = ScreenshotViewer.this.getSelectDrawToolbar();
                if (drawTool == 0)
                {
                  int[] history = new int[3];
                  history[0] = 5;
                  history[1] = scaledX;
                  history[2] = scaledY;
                  historyMouseEvent.add(history);
                }
                else
                {
                  int[] history = (int[])historyMouseEvent.get(historyMouseEvent.size() - 1);
                  if (history[0] == 5)
                  {
                    history[1] = scaledX;
                    history[2] = scaledY;
                  }
                  else
                  {
   
1 2 3 4

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd