Пример #1
0
 static {
   ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
   IconFactory icons = IconFactory.getInstance();
   CLOSE_ICON = sharedImages.getImage(ISharedImages.IMG_ETOOL_DELETE);
   EDIT_ICON = icons.getIcon("editPreview"); // $NON-NLS-1$
   ZOOM_IN_ICON = icons.getIcon("zoomplus"); // $NON-NLS-1$
   ZOOM_OUT_ICON = icons.getIcon("zoomminus"); // $NON-NLS-1$
   CLOSE_ICON_WIDTH = CLOSE_ICON.getImageData().width;
   EDIT_ICON_WIDTH = EDIT_ICON.getImageData().width;
   ZOOM_IN_ICON_WIDTH = ZOOM_IN_ICON.getImageData().width;
   ZOOM_OUT_ICON_WIDTH = ZOOM_OUT_ICON.getImageData().width;
 }
  @SuppressWarnings("unused") // SWT constructors have side effects, they are not unused
  private ToolBar createZoomControls() {
    ToolBar toolBar = new ToolBar(this, SWT.FLAT | SWT.RIGHT | SWT.HORIZONTAL);

    IconFactory iconFactory = IconFactory.getInstance();
    mZoomRealSizeButton = new ToolItem(toolBar, SWT.CHECK);
    mZoomRealSizeButton.setToolTipText("Emulate Real Size");
    mZoomRealSizeButton.setImage(iconFactory.getIcon("zoomreal")); // $NON-NLS-1$);
    mZoomRealSizeButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            boolean newState = mZoomRealSizeButton.getSelection();
            if (rescaleToReal(newState)) {
              mZoomOutButton.setEnabled(!newState);
              mZoomResetButton.setEnabled(!newState);
              mZoomInButton.setEnabled(!newState);
              mZoomFitButton.setEnabled(!newState);
            } else {
              mZoomRealSizeButton.setSelection(!newState);
            }
          }
        });

    mZoomFitButton = new ToolItem(toolBar, SWT.PUSH);
    mZoomFitButton.setToolTipText("Zoom to Fit (0)");
    mZoomFitButton.setImage(iconFactory.getIcon("zoomfit")); // $NON-NLS-1$);
    mZoomFitButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            rescaleToFit(true);
          }
        });

    mZoomResetButton = new ToolItem(toolBar, SWT.PUSH);
    mZoomResetButton.setToolTipText("Reset Zoom to 100% (1)");
    mZoomResetButton.setImage(iconFactory.getIcon("zoom100")); // $NON-NLS-1$);
    mZoomResetButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            resetScale();
          }
        });

    // Group zoom in/out separately
    new ToolItem(toolBar, SWT.SEPARATOR);

    mZoomOutButton = new ToolItem(toolBar, SWT.PUSH);
    mZoomOutButton.setToolTipText("Zoom Out (-)");
    mZoomOutButton.setImage(iconFactory.getIcon("zoomminus")); // $NON-NLS-1$);
    mZoomOutButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            rescale(-1);
          }
        });

    mZoomInButton = new ToolItem(toolBar, SWT.PUSH);
    mZoomInButton.setToolTipText("Zoom In (+)");
    mZoomInButton.setImage(iconFactory.getIcon("zoomplus")); // $NON-NLS-1$);
    mZoomInButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            rescale(+1);
          }
        });

    return toolBar;
  }