示例#1
0
 public void keyPressed(KeyEvent event) {
   if (context.getFocused() != this) return;
   applyShortcut(event.keyCode, event.stateMask);
   if (event.character == '\r' && event.stateMask == 0) {
     replaceContent();
   } else if (event.stateMask == (SWT.ALT | SWT.SHIFT)) {
     FigureNavigator nav = navigator();
     try {
       VisualTerm other = null;
       switch (event.keyCode) {
         case SWT.ARROW_UP:
           other =
               (VisualTerm)
                   nav.getLastSmallestDecscendant(
                       nav.getFirstDescendantOfPrevSibling(
                           this, VerticalFlow.class, VisualTerm.class),
                       VisualTerm.class);
           break;
         case SWT.ARROW_DOWN:
           other =
               (VisualTerm)
                   nav.getFirstSmallestDecscendant(
                       nav.getFirstDescendantOfNextSibling(
                           this, VerticalFlow.class, VisualTerm.class),
                       VisualTerm.class);
           break;
         case SWT.ARROW_LEFT:
           other =
               (VisualTerm)
                   nav.getLastSmallestDecscendant(
                       nav.getFirstDescendantOfPrevSibling(
                           this, HorizontalFlow.class, VisualTerm.class),
                       VisualTerm.class);
           break;
         case SWT.ARROW_RIGHT:
           other =
               (VisualTerm)
                   nav.getFirstSmallestDecscendant(
                       nav.getFirstDescendantOfNextSibling(
                           this, HorizontalFlow.class, VisualTerm.class),
                       VisualTerm.class);
           break;
         case SWT.PAGE_UP:
           other = (VisualTerm) nav.getAncestor(getParent(), VisualTerm.class);
           break;
         case SWT.PAGE_DOWN:
         case SWT.HOME:
           other = (VisualTerm) nav.getFirstDescendant(this, VisualTerm.class, false);
           break;
         case SWT.END:
           other = (VisualTerm) nav.getLastDescendant(this, VisualTerm.class);
           break;
       }
       if (other != null) other.focusGained(null);
     } catch (FigureNotFoundException e) {
       // No navigation...
     }
   }
 }
示例#2
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();
      }
    }
  }
示例#3
0
 @Override
 public VisualTerm getFocused() {
   return context.getFocused();
 }