Exemplo n.º 1
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();
      }
    }
  }
Exemplo n.º 2
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.º 3
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);
 }