Exemplo n.º 1
0
 public void lostFocus() {
   setBorder(null);
   context.getTextEditor().setText("");
   context.getTextEditor().setEnabled(false);
   context.getTextEditor().removeFocusListener(this);
   context.getTextEditor().removeKeyListener(this);
   context.setFocused(null);
 }
Exemplo n.º 2
0
  /**
   * Construct a new instance
   *
   * @param term the term containing the descriptor and possibly the visualization mode
   * @param parent the figure in which this figure is placed
   * @throws TermVisualizationException if visualization of the term has failed, e.g., if the query
   *     failed.
   * @throws TermInstantiationException if a visualization object could not be instantiated
   */
  public VisualTerm(Compound term, TermContext parent)
      throws TermVisualizationException, TermInstantiationException {
    context = parent;

    // Register this object with the content
    context.registerTermFigure(path, this);

    try {
      // The first argument is the descriptor, containing the path and additional information
      descriptor = (Compound) term.arg(1);
      if (!descriptor.name().equals("::"))
        System.err.println("Bad descriptor: " + descriptor.name());
      path = ((Compound) descriptor.arg(1)).arg(1);
      if (term.arity() > 1) {
        projType = (Compound) term.arg(2);
      } else {
        projType = Compound.createCompound("cpi#default");
      }

      // Set up the GUI
      setLayoutManager(new FlowLayout());
      setRequestFocusEnabled(true);
      // Create the child figures
      contentFigure = createContentFigure(descriptor);
      add(contentFigure);

      unreg =
          Notifier.instance()
              .register(
                  new Compound("::", path, Compound.createCompound("cpi#path")),
                  new Runnable() {

                    @Override
                    public void run() {
                      try {
                        updateFigure();
                      } catch (TermVisualizationException e) {
                        e.printStackTrace();
                      } catch (TermInstantiationException e) {
                        e.printStackTrace();
                      }
                    }
                  });
    } catch (TermVisualizationException e) {
      e.printStackTrace();
      Label label = new Label("<<<" + e.getMessage() + ">>>");
      label.setForegroundColor(new Color(context.getTextEditor().getDisplay(), 255, 0, 0));
      add(label);
    } catch (ClassCastException e) {
      e.printStackTrace();
      Label label = new Label("<<<" + e.getMessage() + ">>>");
      label.setForegroundColor(new Color(context.getTextEditor().getDisplay(), 128, 128, 0));
      add(label);
    }
    pathOwner.put(path, this);
  }
Exemplo n.º 3
0
 private void replaceContent() {
   try {
     setContentFromString(context.getTextEditor().getText());
   } catch (TermVisualizationException e) {
     ErrorDialog.openError(
         context.getTextEditor().getShell(),
         "Error Updating Element",
         "The following error has occured: " + e.getMessage(),
         Status.OK_STATUS);
   } catch (PrologException e) {
     e.printStackTrace();
   } catch (TermInstantiationException e) {
     e.printStackTrace();
   } catch (ExecutionContextException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 4
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.º 5
0
 public void mousePressed(MouseEvent me) {
   if (me.button == 3) {
     // Context menu
     try {
       createContextMenu(me);
     } catch (TermInstantiationException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   } else {
     // Gain focus
     if (canFocus()) {
       requestFocus();
       context.getTextEditor().setEnabled(true);
       context.getTextEditor().addFocusListener(this);
       context.getTextEditor().setFocus();
     } else {
       context.handleClick(me);
     }
   }
 }
Exemplo n.º 6
0
 public Text getTextEditor() {
   return context.getTextEditor();
 }