public CompileOutputBufferWithHighlight() {
    styles_ = ConsoleResources.INSTANCE.consoleStyles();

    output_ = new PreWidget();
    output_.setStylePrimaryName(styles_.output());
    output_.addStyleName("ace_text-layer");
    output_.addStyleName("ace_line");
    output_.addStyleName(styles_.paddedOutput());
    FontSizer.applyNormalFontSize(output_);

    scrollPanel_ = new BottomScrollPanel();
    scrollPanel_.setSize("100%", "100%");
    scrollPanel_.addStyleName("ace_editor");
    scrollPanel_.addStyleName("ace_scroller");
    scrollPanel_.setWidget(output_);

    initWidget(scrollPanel_);
  }
Пример #2
0
  public HistoryTable(
      String commandClassName,
      String timestampClassName,
      String selectedClassName,
      TimestampMode timestampMode,
      final Commands commands) {
    super(
        new HistoryEntryItemCodec(
            commandClassName,
            timestampClassName,
            timestampMode,
            timestampMode == TimestampMode.ITEM),
        selectedClassName,
        true,
        true);

    searchResult_ = timestampMode == TimestampMode.ITEM;

    applyWidthConstraints();

    final Resources res = GWT.create(Resources.class);
    setStyleName(res.styles().historyTable());
    FontSizer.applyNormalFontSize(this);

    if (searchResult_) {
      addMouseDownHandler(
          new MouseDownHandler() {
            public void onMouseDown(MouseDownEvent event) {
              Element el = DOM.eventGetTarget((Event) event.getNativeEvent());
              if (el != null
                  && el.getTagName().equalsIgnoreCase("div")
                  && el.getClassName().equals(res.styles().disclosure())) {
                // disclosure click
                commands.historyShowContext().execute();
              }
            }
          });
    }
  }
Пример #3
0
  @Override
  protected Widget createMainWidget() {
    context_ = new FindResultContext();

    FindOutputResources resources = GWT.create(FindOutputResources.class);
    resources.styles().ensureInjected();

    table_ =
        new FastSelectTable<FindResult, CodeNavigationTarget, Object>(
            new FindOutputCodec(resources), resources.styles().selectedRow(), true, false);
    FontSizer.applyNormalFontSize(table_);
    table_.addStyleName(resources.styles().findOutput());
    table_.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) return;

            if (dblClick_.checkForDoubleClick(event.getNativeEvent())) fireSelectionCommitted();
          }

          private final DoubleClickState dblClick_ = new DoubleClickState();
        });

    table_.addKeyDownHandler(
        new KeyDownHandler() {
          @Override
          public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) fireSelectionCommitted();
            event.stopPropagation();
            event.preventDefault();
          }
        });

    scrollPanel_ = new ScrollPanel(table_);
    scrollPanel_.setSize("100%", "100%");
    return scrollPanel_;
  }
Пример #4
0
  public int getCharacterWidth() {
    // create width checker label and add it to the root panel
    Label widthChecker = new Label();
    widthChecker.setStylePrimaryName(styles_.console());
    FontSizer.applyNormalFontSize(widthChecker);
    RootPanel.get().add(widthChecker, -1000, -1000);

    // put the text into the label, measure it, and remove it
    String text = new String("abcdefghijklmnopqrstuvwzyz0123456789");
    widthChecker.setText(text);
    int labelWidth = widthChecker.getOffsetWidth();
    RootPanel.get().remove(widthChecker);

    // compute the points per character
    int pointsPerCharacter = labelWidth / text.length();

    // compute client width
    int clientWidth = getElement().getClientWidth();
    int offsetWidth = getOffsetWidth();
    if (clientWidth == offsetWidth) {
      // if the two widths are the same then there are no scrollbars.
      // however, we know there will eventually be a scrollbar so we
      // should offset by an estimated amount
      // (is there a more accurate way to estimate this?)
      final int ESTIMATED_SCROLLBAR_WIDTH = 19;
      clientWidth -= ESTIMATED_SCROLLBAR_WIDTH;
    }

    // compute character width (add pad so characters aren't flush to right)
    final int RIGHT_CHARACTER_PAD = 2;
    int width = (clientWidth / pointsPerCharacter) - RIGHT_CHARACTER_PAD;

    // enforce a minimum width
    final int MINIMUM_WIDTH = 30;
    return Math.max(width, MINIMUM_WIDTH);
  }
Пример #5
0
  public ShellWidget(AceEditor editor) {
    styles_ = ConsoleResources.INSTANCE.consoleStyles();

    SelectInputClickHandler secondaryInputHandler = new SelectInputClickHandler();

    output_ = new PreWidget();
    output_.setStylePrimaryName(styles_.output());
    output_.addClickHandler(secondaryInputHandler);

    pendingInput_ = new PreWidget();
    pendingInput_.setStyleName(styles_.output());
    pendingInput_.addClickHandler(secondaryInputHandler);

    prompt_ = new HTML();
    prompt_.setStylePrimaryName(styles_.prompt());
    prompt_.addStyleName(KEYWORD_CLASS_NAME);

    input_ = editor;
    input_.setShowLineNumbers(false);
    input_.setShowPrintMargin(false);
    if (!Desktop.isDesktop()) input_.setNewLineMode(NewLineMode.Unix);
    input_.setUseWrapMode(true);
    input_.setPadding(0);
    input_.autoHeight();
    final Widget inputWidget = input_.asWidget();
    input_.addClickHandler(secondaryInputHandler);
    inputWidget.addStyleName(styles_.input());
    input_.addCursorChangedHandler(
        new CursorChangedHandler() {
          public void onCursorChanged(CursorChangedEvent event) {
            Scheduler.get()
                .scheduleDeferred(
                    new ScheduledCommand() {
                      @Override
                      public void execute() {
                        input_.scrollToCursor(scrollPanel_, 8, 60);
                      }
                    });
          }
        });
    input_.addCapturingKeyDownHandler(
        new KeyDownHandler() {
          @Override
          public void onKeyDown(KeyDownEvent event) {
            // If the user hits Page-Up from inside the console input, we need
            // to simulate pageup because focus is not contained in the scroll
            // panel (it's in the hidden textarea that Ace uses under the
            // covers).

            int keyCode = event.getNativeKeyCode();
            switch (keyCode) {
              case KeyCodes.KEY_PAGEUP:
                event.stopPropagation();
                event.preventDefault();

                // Can't scroll any further up. Return before we change focus.
                if (scrollPanel_.getVerticalScrollPosition() == 0) return;

                scrollPanel_.focus();
                int newScrollTop =
                    scrollPanel_.getVerticalScrollPosition() - scrollPanel_.getOffsetHeight() + 40;
                scrollPanel_.setVerticalScrollPosition(Math.max(0, newScrollTop));
                break;
            }
          }
        });

    inputLine_ = new DockPanel();
    inputLine_.setHorizontalAlignment(DockPanel.ALIGN_LEFT);
    inputLine_.setVerticalAlignment(DockPanel.ALIGN_TOP);
    inputLine_.add(prompt_, DockPanel.WEST);
    inputLine_.setCellWidth(prompt_, "1");
    inputLine_.add(input_.asWidget(), DockPanel.CENTER);
    inputLine_.setCellWidth(input_.asWidget(), "100%");
    inputLine_.setWidth("100%");

    verticalPanel_ = new VerticalPanel();
    verticalPanel_.setStylePrimaryName(styles_.console());
    verticalPanel_.addStyleName("ace_text-layer");
    verticalPanel_.addStyleName("ace_line");
    FontSizer.applyNormalFontSize(verticalPanel_);
    verticalPanel_.add(output_);
    verticalPanel_.add(pendingInput_);
    verticalPanel_.add(inputLine_);
    verticalPanel_.setWidth("100%");

    scrollPanel_ = new ClickableScrollPanel();
    scrollPanel_.setWidget(verticalPanel_);
    scrollPanel_.addStyleName("ace_editor");
    scrollPanel_.addStyleName("ace_scroller");
    scrollPanel_.addClickHandler(secondaryInputHandler);
    scrollPanel_.addKeyDownHandler(secondaryInputHandler);

    secondaryInputHandler.setInput(editor);

    scrollToBottomCommand_ =
        new TimeBufferedCommand(5) {
          @Override
          protected void performAction(boolean shouldSchedulePassive) {
            if (!DomUtils.selectionExists()) scrollPanel_.scrollToBottom();
          }
        };

    initWidget(scrollPanel_);

    addCopyHook(getElement());
  }