public Point getViewportOrigin() {
   Point result = new Point(0, 0);
   Viewport viewport = getViewPort();
   if (viewport != null) {
     result = new Point(viewport.getClientArea().getLocation());
   }
   return result;
 }
Exemplo n.º 2
0
 private void disposeRulerViewer(GraphicalViewer viewer) {
   if (viewer == null) return;
   /*
    * There's a tie from the editor's range model to the RulerViewport (via
    * a listener) to the RulerRootEditPart to the RulerViewer. Break this
    * tie so that the viewer doesn't leak and can be garbage collected.
    */
   RangeModel rModel = new DefaultRangeModel();
   Viewport port = ((FigureCanvas) viewer.getControl()).getViewport();
   port.setHorizontalRangeModel(rModel);
   port.setVerticalRangeModel(rModel);
   rulerEditDomain.removeViewer(viewer);
   viewer.getControl().dispose();
 }
Exemplo n.º 3
0
  public void initStepDat() {
    Viewport port = ((FigureCanvas) getControl()).getViewport();
    stepData.minX = port.getHorizontalRangeModel().getMinimum();
    stepData.maxX = port.getHorizontalRangeModel().getMaximum();
    stepData.valueX = port.getHorizontalRangeModel().getValue();
    stepData.extendX = port.getHorizontalRangeModel().getExtent();

    stepData.minY = port.getVerticalRangeModel().getMinimum();
    stepData.maxY = port.getVerticalRangeModel().getMaximum();
    stepData.valueY = port.getVerticalRangeModel().getValue();
    stepData.extendY = port.getVerticalRangeModel().getExtent();
  }
Exemplo n.º 4
0
  // We override reveal to show the Handles of the selected EditPart when
  // scrolling
  public void reveal(EditPart part) {
    // In some case, the editor control is not created, but get the sync selection event.
    // Fix this problem temporary.
    if (getFigureCanvas() == null || getFigureCanvas().isDisposed()) {
      return;
    }

    Viewport port = getFigureCanvas().getViewport();
    IFigure target = ((GraphicalEditPart) part).getFigure();

    Rectangle exposeRegion = target.getBounds().getCopy();

    // Get the primary editpolicy
    EditPolicy policy = part.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);

    // If the policy let us access the handles, proceed, otherwise
    // default to original behaviour
    if (!(policy instanceof ISelectionHandlesEditPolicy)) {
      super.reveal(part);
      return;
    }

    // First translate exposeRegion to the root level
    target = target.getParent();
    while (target != null && target != port) {
      target.translateToParent(exposeRegion);
      target = target.getParent();
    }

    // Merge selection handles if any to the exposeRegion
    List handles = ((ISelectionHandlesEditPolicy) policy).getHandles();
    for (Iterator iter = handles.iterator(); iter.hasNext(); ) {
      AbstractHandle handle = (AbstractHandle) iter.next();

      Locator locator = handle.getLocator();
      locator.relocate(handle);
      exposeRegion.union(handle.getBounds().getCopy());
    }

    exposeRegion.getExpanded(5, 5);

    Dimension viewportSize = port.getClientArea().getSize();

    Point topLeft = exposeRegion.getTopLeft();
    Point bottomRight = exposeRegion.getBottomRight().translate(viewportSize.getNegated());
    Point finalLocation = new Point();
    if (viewportSize.width < exposeRegion.width)
      finalLocation.x = Math.min(bottomRight.x, Math.max(topLeft.x, port.getViewLocation().x));
    else finalLocation.x = Math.min(topLeft.x, Math.max(bottomRight.x, port.getViewLocation().x));

    if (viewportSize.height < exposeRegion.height)
      finalLocation.y = Math.min(bottomRight.y, Math.max(topLeft.y, port.getViewLocation().y));
    else finalLocation.y = Math.min(topLeft.y, Math.max(bottomRight.y, port.getViewLocation().y));

    getFigureCanvas().scrollSmoothTo(finalLocation.x, finalLocation.y);
  }
Exemplo n.º 5
0
 /**
  * Sets zoom to the passed string. The string must be composed of numeric characters only with the
  * exception of a decimal point and a '%' as the last character. If the zoom level contribution
  * list has been set, this method should be overridden to provide the appropriate zoom
  * implementation for the new zoom levels.
  *
  * @param zoomString The new zoom level
  */
 public void setZoomAsText(String zoomString) {
   currentZoomContant = null;
   if (zoomString.equalsIgnoreCase(FIT_HEIGHT)) {
     currentZoomContant = FIT_HEIGHT;
     primSetZoom(getFitHeightZoomLevel());
     viewport.getUpdateManager().performUpdate();
     viewport.setViewLocation(
         viewport.getHorizontalRangeModel().getValue(),
         viewport.getVerticalRangeModel().getMinimum());
   } else if (zoomString.equalsIgnoreCase(FIT_ALL)) {
     currentZoomContant = FIT_ALL;
     primSetZoom(getFitPageZoomLevel());
     viewport.getUpdateManager().performUpdate();
     viewport.setViewLocation(
         viewport.getHorizontalRangeModel().getMinimum(),
         viewport.getVerticalRangeModel().getMinimum());
   } else if (zoomString.equalsIgnoreCase(FIT_WIDTH)) {
     currentZoomContant = FIT_WIDTH;
     primSetZoom(getFitWidthZoomLevel());
     viewport.getUpdateManager().performUpdate();
     viewport.setViewLocation(
         viewport.getHorizontalRangeModel().getMinimum(),
         viewport.getVerticalRangeModel().getValue());
   } else {
     try {
       // Trim off the '%'
       if (zoomString.charAt(zoomString.length() - 1) == '%') {
         zoomString = zoomString.substring(0, zoomString.length() - 1);
       }
       double newZoom = Double.parseDouble(zoomString) / 100;
       setZoom(newZoom / multiplier);
     } catch (Exception e) {
       Display.getCurrent().beep();
     }
   }
 }
Exemplo n.º 6
0
 /**
  * Sets the Viewport's view associated with this ZoomManager to the passed Point
  *
  * @param p The new location for the Viewport's view.
  */
 public void setViewLocation(Point p) {
   viewport.setViewLocation(p.x, p.y);
 }
  /**
   * Ask for a file name and save the viewer containing the currently selected GraphicalEditPart to
   * a image file.
   */
  @Override
  public void run() {
    final IEditorInput editorInput =
        (IEditorInput) getWorkbenchPart().getAdapter(IEditorInput.class);
    final SaveAsDialog dialog = new SaveAsDialog(new Shell(Display.getDefault()));
    dialog.setBlockOnOpen(true);
    if (editorInput == null) {
      dialog.setOriginalName("viewerImage" + counter + ".png");
    } else {
      final String fileName = editorInput.getName();
      final int extensionPos = fileName.lastIndexOf(".");
      dialog.setOriginalName(fileName.substring(0, extensionPos) + ".png");
    }
    dialog.create();
    dialog.setMessage(
        "If you don't choose an extension png will be used a default. "
            + "\n"
            + "Export is limited to file size of 15MByte -> you may use file ..(read more) "
            + "\n"
            + "type svg for very large graphs."
            + "\n"
            + "After export the workspace needs a manual refresh to show new image file.");
    dialog.setTitle("Specify file to export viewer image (png, jpeg, bmp, svg)");
    dialog.open();
    if (Window.CANCEL == dialog.getReturnCode()) {
      return;
    }

    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IPath path = root.getLocation().append(dialog.getResult());

    int format;
    final String ext = path.getFileExtension();
    if (ext.equals("png")) {
      format = SWT.IMAGE_PNG;
      // GIFs work only with 8Bit and not with 32 Bits color depth
      //		} else if (ext.equals("gif")) {
      //			format = SWT.IMAGE_GIF;
    } else if (ext.equals("jpeg")) {
      format = SWT.IMAGE_JPEG;
    } else if (ext.equals("bmp")) {
      format = SWT.IMAGE_BMP;
      // } else if (ext.equals("ico")) {
      // format = SWT.IMAGE_ICO;
    } else if (ext.equalsIgnoreCase("svg")) {
      format = SWT.IMAGE_UNDEFINED; // TODO: find a more appropriate constant for representing SVGs
    } else {
      MessageDialog.openError(
          null,
          "Invalid file extension!",
          "The specified extension ("
              + ext
              + ") is not a valid image format extension.\nPlease use png, jpeg, bmp or svg!");
      return;
    }

    IFigure figure = ((SimpleRootEditPart) viewer.getRootEditPart()).getFigure();
    if (figure instanceof Viewport) {
      // This seems to trim the figure to the smallest rectangle containing all child figures
      ((Viewport) figure).setSize(1, 1);
      ((Viewport) figure).validate();
      figure = ((Viewport) figure).getContents();
    }
    if (format == SWT.IMAGE_UNDEFINED) {
      try {
        final File file = path.toFile();
        this.exportToSVG(file, figure);
      } catch (final IOException e) {
        e.printStackTrace();
      }
    } else {
      final byte[] imageCode = createImage(figure, format);
      try {
        final File file = path.toFile();
        final FileOutputStream fos = new FileOutputStream(file);
        fos.write(imageCode);
        fos.flush();
        fos.close();
        counter++;
      } catch (final IOException e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 8
0
  public void focusGained(org.eclipse.swt.events.FocusEvent event) {
    VisualTerm previousFocused = context.getFocused();
    if (previousFocused != null) previousFocused.lostFocus();
    context.setFocused(this);

    LineBorder focusBorder = new LineBorder();
    focusBorder.setStyle(Graphics.LINE_DASH);
    focusBorder.setColor(getColor());
    focusBorder.setWidth(1);
    setBorder(focusBorder);
    context.selectionChanged(this);
    if (canModify()) {
      try {
        String text = termToText();
        context.getTextEditor().setText(text);
        context.getTextEditor().setEnabled(true);
        context.getTextEditor().setSelection(0, text.length());
        context.getTextEditor().addKeyListener(this);
        context.getTextEditor().setFocus();
        Viewport viewport = ((FigureCanvas) getCanvas()).getViewport();
        Point p = viewport.getViewLocation();
        if (p.y > getLocation().y) {
          viewport.setViewLocation(new Point(p.x, getLocation().y));
        } else if (p.y + viewport.getSize().height < getLocation().y + getSize().height
            && viewport.getSize().height > getSize().height) {
          viewport.setViewLocation(
              new Point(p.x, getLocation().y + getSize().height - viewport.getSize().height));
        }
        if (p.x > getLocation().x) {
          viewport.setViewLocation(new Point(getLocation().x, p.y));
        } else if (p.x + viewport.getSize().width < getLocation().x + getSize().width
            && viewport.getSize().width > getSize().width) {
          viewport.setViewLocation(
              new Point(getLocation().x + getSize().width - viewport.getSize().width, p.y));
        }
      } catch (IOException e) {
        e.printStackTrace();
      } catch (PrologException e) {
        e.printStackTrace();
      } catch (TermInstantiationException e) {
        e.printStackTrace();
      } catch (ExecutionContextException e) {
        e.printStackTrace();
      }
    }
  }