コード例 #1
0
ファイル: BentoHighlighting.java プロジェクト: jesusc/bento
 private void addListeners(bento.language.bentocomp.resource.bento.ui.BentoEditor editor) {
   UpdateHighlightingListener hl = new UpdateHighlightingListener();
   textWidget.addKeyListener(hl);
   textWidget.addVerifyListener(hl);
   textWidget.addMouseListener(hl);
   editor.addBackgroundParsingListener(hl);
 }
コード例 #2
0
  /**
   * Installs this highlighter into the specified StyledText object. Client can manually call
   * detach() method, then wants to destroy this object.
   */
  public void attach(StyledText parent) {
    detach();

    text = parent;
    text.addDisposeListener(ml);
    text.addLineStyleListener(ml);
    text.addLineBackgroundListener(ml);
    text.addPaintListener(ml);
    text.addVerifyListener(ml);
    text.addExtendedModifyListener(ml);
    text.addControlListener(ml);
    text.addKeyListener(ml);
    text.addTraverseListener(ml);
    text.addMouseListener(ml);
    text.addSelectionListener(ml);
    text.getContent().addTextChangeListener(ml);
    ScrollBar sb = text.getVerticalBar();
    if (sb != null) sb.addSelectionListener(ml);
    updateViewport();

    new Thread() {
      public void run() {
        // setPriority(Thread.NORM_PRIORITY-1);
        while (true) {
          try {
            sleep(300);
          } catch (InterruptedException e) {
          }
          if (baseEditor == null || text == null) break;
          if (backParserDelay) {
            backParserDelay = false;
            try {
              sleep(1500);
            } catch (InterruptedException e) {
            }
            continue;
          }
          ;
          Display.getDefault()
              .syncExec(
                  new Runnable() {
                    public void run() {
                      if (baseEditor == null || text == null) return;
                      if (text.isDisposed()) return;
                      // System.out.println(System.currentTimeMillis());
                      baseEditor.idleJob(80);
                      // redrawFrom(text.getLineAtOffset(text.getCaretOffset()));
                    }
                  });
        }
        ;
      };
    }.start();
  }
コード例 #3
0
  /** DOC amaumont Comment method "addListeners". */
  private void addListeners() {
    styledText.addFocusListener(
        new FocusListener() {

          public void focusGained(FocusEvent e) {
            refreshProposalSize();
          }

          public void focusLost(FocusEvent e) {}
        });

    styledText.addControlListener(
        new ControlListener() {

          public void controlMoved(ControlEvent e) {}

          public void controlResized(ControlEvent e) {
            refreshProposalSize();
          }
        });

    styledText.addExtendedModifyListener(
        new ExtendedModifyListener() {

          public void modifyText(ExtendedModifyEvent event) {
            updateCellExpression();
            // System.out.println("ExtendedModifyListener modify text");

          }
        });
    styledText
        .getContent()
        .addTextChangeListener(
            new TextChangeListener() {

              public void textChanged(TextChangedEvent event) {
                highlightLineOfCursorPosition(styledText.getSelection());
              }

              public void textChanging(TextChangingEvent event) {
                // System.out.println("textChanging");
              }

              public void textSet(TextChangedEvent event) {
                // System.out.println("textSet");
              }
            });
    styledText.addModifyListener(
        new ModifyListener() {

          public void modifyText(ModifyEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
          }
        });

    styledText.addKeyListener(
        new KeyListener() {

          public void keyPressed(KeyEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
          }

          public void keyReleased(KeyEvent e) {
            // TODO Auto-generated method stub

          }
        });

    styledText.addVerifyKeyListener(
        new VerifyKeyListener() {

          public void verifyKey(VerifyEvent verifyEvent) {
            if (verifyEvent.character == '\r'
                && contentProposalAdapter != null
                && contentProposalAdapter.isProposalOpened()) {
              verifyEvent.doit = false;
            } else {
              verifyEvent.doit = true;
            }
          }
        });

    styledText.addMouseListener(
        new MouseListener() {

          public void mouseDoubleClick(MouseEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
          }

          public void mouseDown(MouseEvent e) {
            highlightLineOfCursorPosition(styledText.getSelection());
          }

          public void mouseUp(MouseEvent e) {}
        });
  }
コード例 #4
0
  CommitMessageViewer(final Composite parent, final IPageSite site, IWorkbenchPartSite partSite) {
    super(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
    this.partSite = partSite;

    final StyledText t = getTextWidget();
    t.setFont(UIUtils.getFont(UIPreferences.THEME_CommitMessageFont));

    sys_normalCursor = t.getCursor();

    // set the cursor when hovering over a link
    t.addListener(
        SWT.MouseMove,
        new Listener() {
          public void handleEvent(final Event e) {
            if (getStyleRange(e.x, e.y) instanceof ObjectLink) t.setCursor(SYS_LINK_CURSOR);
            else t.setCursor(sys_normalCursor);
          }
        });
    // react on link click
    t.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(final MouseEvent e) {
            // only process the hyper link if it was a primary mouse click
            if (e.button != 1) return;

            final StyleRange r = getStyleRange(e.x, e.y);
            if (r instanceof ObjectLink) {
              final RevCommit c = ((ObjectLink) r).targetCommit;
              for (final Object l : navListeners.getListeners())
                ((CommitNavigationListener) l).showCommit(c);
            }
          }
        });
    setTextDoubleClickStrategy(
        new DefaultTextDoubleClickStrategy(), IDocument.DEFAULT_CONTENT_TYPE);
    activatePlugins();

    // react on changes in the fill and wrap preferences
    listener =
        new IPropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_WRAP)) {
              setWrap(((Boolean) event.getNewValue()).booleanValue());
              return;
            }
            if (event.getProperty().equals(UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_FILL)) {
              setFill(((Boolean) event.getNewValue()).booleanValue());
              return;
            }
            if (event.getProperty().equals(UIPreferences.HISTORY_SHOW_TAG_SEQUENCE)) {
              format();
              return;
            }
          }
        };

    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    store.addPropertyChangeListener(listener);
    fill = store.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_FILL);
    setWrap(store.getBoolean(UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_WRAP));

    // global action handlers for select all and copy
    final IAction selectAll =
        new Action() {
          @Override
          public void run() {
            doOperation(ITextOperationTarget.SELECT_ALL);
          }

          @Override
          public boolean isEnabled() {
            return canDoOperation(ITextOperationTarget.SELECT_ALL);
          }
        };

    final IAction copy =
        new Action() {
          @Override
          public void run() {
            doOperation(ITextOperationTarget.COPY);
          }

          @Override
          public boolean isEnabled() {
            return canDoOperation(ITextOperationTarget.COPY);
          }
        };
    // register and unregister the global actions upon focus events
    getControl()
        .addFocusListener(
            new FocusListener() {
              public void focusLost(FocusEvent e) {
                site.getActionBars().setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), null);
                site.getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(), null);
                site.getActionBars().updateActionBars();
              }

              public void focusGained(FocusEvent e) {
                site.getActionBars()
                    .setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), selectAll);
                site.getActionBars().setGlobalActionHandler(ActionFactory.COPY.getId(), copy);
                site.getActionBars().updateActionBars();
              }
            });

    final MenuManager mgr = new MenuManager();
    Control c = getControl();
    c.setMenu(mgr.createContextMenu(c));

    IPersistentPreferenceStore pstore = (IPersistentPreferenceStore) store;

    Action showTagSequence =
        new BooleanPrefAction(
            pstore,
            UIPreferences.HISTORY_SHOW_TAG_SEQUENCE,
            UIText.ResourceHistory_ShowTagSequence) {
          @Override
          protected void apply(boolean value) {
            // nothing, just toggle
          }
        };
    mgr.add(showTagSequence);

    Action wrapComments =
        new BooleanPrefAction(
            pstore,
            UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_WRAP,
            UIText.ResourceHistory_toggleCommentWrap) {
          @Override
          protected void apply(boolean value) {
            // nothing, just toggle
          }
        };
    mgr.add(wrapComments);

    Action fillParagraphs =
        new BooleanPrefAction(
            pstore,
            UIPreferences.RESOURCEHISTORY_SHOW_COMMENT_FILL,
            UIText.ResourceHistory_toggleCommentFill) {
          @Override
          protected void apply(boolean value) {
            // nothing, just toggle
          }
        };
    mgr.add(fillParagraphs);
  }
コード例 #5
0
  private void initialize(final Composite inContainer) {
    textWidget =
        new StyledText(
            inContainer,
            SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);

    content = new TextContent();
    textWidget.setContent(content);
    textWidget.setLayout(new GridLayout(1, true));
    textWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    textWidget.addExtendedModifyListener(
        new ExtendedModifyListener() {
          @Override
          public void modifyText(final ExtendedModifyEvent inEvent) {
            if (textWidget.getCharCount() == 0) return;
            final StyleRange lRange =
                textWidget.getStyleRangeAtOffset(Math.max(inEvent.start - 1, 0));
            if (lRange != null) {
              final StyleRange lNew =
                  new StyleRange(
                      lRange.start,
                      lRange.length + inEvent.length,
                      lRange.foreground,
                      lRange.background,
                      lRange.fontStyle);
              textWidget.replaceStyleRanges(lNew.start, lNew.length, new StyleRange[] {lNew});
            }
            final int lEndPos = inEvent.start + inEvent.length;
            if (lEndPos - textWidget.getOffsetAtLine(textWidget.getLineAtOffset(lEndPos)) == 0) {
              final int lLineIndex = textWidget.getLineAtOffset(inEvent.start);
              if (lLineIndex + 2 > textWidget.getLineCount()) return;
              // a new line has been entered, therefore, check whether we
              // have to continue a list
              final Bullet lBullet = textWidget.getLineBullet(lLineIndex);
              textWidget.setLineBullet(lLineIndex + 1, 1, lBullet);
            }
          }
        });
    textWidget.addPaintObjectListener(Styles.getPaintObjectListener(textWidget));
    textWidget.addVerifyKeyListener(
        new VerifyKeyListener() {
          @Override
          public void verifyKey(final VerifyEvent inEvent) {
            if (inEvent.keyCode == 9) { // TAB keyCode
              final StyledText lWidget = (StyledText) inEvent.getSource();
              if (consumeTabKey(lWidget)) {
                inEvent.doit = false;
                final TextStyler lStyler = new TextStyler(lWidget);
                if ((inEvent.stateMask & SWT.SHIFT) != 0) {
                  lStyler.dedentLines();
                  provider.notifyPositionChange(lWidget.getCaretOffset());
                } else {
                  lStyler.indentLines();
                }
              }
            }
          }
        });
    textWidget.addTraverseListener(
        new TraverseListener() {
          @Override
          public void keyTraversed(final TraverseEvent inEvent) {
            if (inEvent.detail == SWT.TRAVERSE_TAB_PREVIOUS
                && consumeTabKey((StyledText) inEvent.getSource())) {
              inEvent.doit = false;
            }
          }
        });
    textWidget.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(final MouseEvent inEvent) {
            provider.notifyPositionChange(textWidget.getCaretOffset());
          }
        });
    textWidget.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(final KeyEvent inEvent) {
            provider.notifyPositionChange(textWidget.getCaretOffset());
          }
        });
    provider = ContextInjectionFactory.make(TextStyleProvider.class, context);
    provider.setWidget(textWidget);

    // font handling
    if (fontSizeToUse != 0) {
      trackFontSize(fontSizeToUse);
    }

    disposed = false;
  }