예제 #1
0
  /**
   * ************************************************************************* Shows a prompt
   * prepared to receive an answer (controlling GUI)
   * ************************************************************************
   */
  private void promptAsControlling() {

    boolean defaultOptionSet = false;

    if (m_promptData.isList()) {
      m_expected = m_promptData.getExpected();
      m_numericInput = false;
      // Set the prompt text
      m_promptText.setText(m_promptData.getText());

      // Adjust the height and visibility of scroll bar depending on
      // the control doing text wrapping or not
      int areaWidth = m_promptText.getClientArea().width;
      GC gc = new GC(m_promptText);
      int textWidth = gc.getFontMetrics().getAverageCharWidth() * m_promptText.getText().length();
      boolean wrapping = textWidth >= areaWidth;
      gc.dispose();
      m_promptText.getVerticalBar().setVisible(wrapping);
      if (wrapping) {
        GridData gd = (GridData) m_promptText.getLayoutData();
        gd.heightHint = 45;
        layout();
      }

      m_promptDisplayType = m_promptData.getPromptDisplayType();
      // Build the option list and show the option composite
      defaultOptionSet =
          updateOptions(
              m_promptData.getOptions(), m_promptData.getExpected(), m_promptData.getDefault());
      if (defaultOptionSet) {
        m_textInput.setValue(m_promptData.getDefault());
      }

    } else {
      // Not a List

      m_expected = null;
      m_promptText.setText(m_promptData.getText());
      m_numericInput = m_promptData.isNumeric();
      if (!m_promptData.getDefault().isEmpty()) {
        m_textInput.setValue(m_promptData.getDefault());
        defaultOptionSet = true;
      }
    }

    setHint();

    if (defaultOptionSet) {
      // If we have a default option preselected, enable the controls
      m_commitButton.setEnabled(true);
      m_resetButton.setEnabled(true);
    } else {
      // Reset the console input

      m_textInput.reset();
    }
    // Set the focus, highlighting
    m_textInput.promptStart();
  }
예제 #2
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.jface.fieldassist.IControlContentAdapter#getInsertionBounds(org.eclipse.swt.widgets.Control)
  */
 public Rectangle getInsertionBounds(Control control) {
   Text text = (Text) control;
   Point caretOrigin = text.getCaretLocation();
   // We fudge the y pixels due to problems with getCaretLocation
   // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=52520
   return new Rectangle(
       caretOrigin.x + text.getClientArea().x,
       caretOrigin.y + text.getClientArea().y + 3,
       1,
       text.getLineHeight());
 }
예제 #3
0
  /** Expand/contract all blocks currently on screen */
  public void expandPage(boolean state) {
    // Get all the information about which part of the text window is
    // visible
    int topLine = m_Text.getTopIndex();
    int lineHeight = m_Text.getLineHeight();
    int visibleLines = m_Text.getClientArea().height / lineHeight;
    int lastLine = Math.min(m_Text.getLineCount(), m_Text.getTopIndex() + visibleLines);

    boolean atBottom = (lastLine == m_Text.getLineCount());

    // Start with the first block that starts at topLine or includes
    // topLine.
    Block topBlock = m_FoldingDoc.getBlockByLineNumber(topLine);
    Block bottomBlock = m_FoldingDoc.getBlockByLineNumber(lastLine);

    if (topBlock == null) return;

    // Stop redrawing while we expand/collapse everything then turn it back
    // on
    setRedraw(false);

    // If the lastLine is after the bottom block, use the last block in the
    // document
    if (bottomBlock == null)
      bottomBlock = m_FoldingDoc.getBlock(m_FoldingDoc.getNumberBlocks() - 1);

    int topIndex = topBlock.getIndex();
    int bottomIndex = bottomBlock.getIndex();

    for (int i = topIndex; i <= bottomIndex; i++) {
      Block block = m_FoldingDoc.getBlock(i);
      m_FoldingDoc.expandBlock(block, state);
    }

    // If the selection was set to the bottom before we expanded make sure
    // it stays there after the expansion.
    if (state && atBottom) scrollBottom();

    // Redraw everything
    setRedraw(true);
  }
예제 #4
0
  protected void paintIcons(PaintEvent e) {
    // Check if we've turned off redraws
    if (m_DrawingDisabled) return;

    GC gc = e.gc;

    Rectangle client = m_IconBar.getClientArea();

    // Make sure the text control is properly initialized
    if (m_Text.getLineHeight() == 0) return;

    // Get all the information about which part of the text window is
    // visible
    int topLine = m_Text.getTopIndex();
    int lineHeight = m_Text.getLineHeight();
    int visibleLines = m_Text.getClientArea().height / lineHeight;
    int lastLine = Math.min(m_Text.getLineCount(), m_Text.getTopIndex() + visibleLines);

    // Start with the first block that starts at topLine or includes
    // topLine.
    Block topBlock = m_FoldingDoc.getBlockByLineNumber(topLine);
    int blockCount = m_FoldingDoc.getNumberBlocks();

    if (topBlock == null) return;

    int blockIndex = topBlock.getIndex();

    int outerSize = 9;
    int innerSize = 6;
    int offset = (outerSize - innerSize) / 2 + 1;

    Color gray = m_IconBar.getDisplay().getSystemColor(SWT.COLOR_GRAY);
    Color black = m_IconBar.getDisplay().getSystemColor(SWT.COLOR_BLACK);

    // Go through each block in turn until we're off the bottom of the
    // screen
    // or at the end of the list of blocks drawing icons
    while (blockIndex != -1 && blockIndex < blockCount) {
      Block block = m_FoldingDoc.getBlock(blockIndex);

      int line = block.getStart();

      // Once we drop off the bottom of the screen we're done
      if (line >= lastLine) break;

      int pos = line - topLine;
      int y = pos * lineHeight + (lineHeight / 2) - (outerSize / 2) - 1;
      int x = 1;

      boolean expanded = block.isExpanded();

      if (block.canExpand()) {
        gc.drawRectangle(x, y, x + outerSize, x + outerSize);

        // Start with a - sign
        int y1 = y + 1 + (outerSize / 2);
        gc.drawLine(x + offset, y1, x + offset + innerSize, y1);

        if (!expanded) {
          // If not expanded turn the - into a +
          int x1 = x + 1 + (outerSize / 2);
          gc.drawLine(x1, y + offset, x1, y + offset + innerSize);
        } else {
          // If expanded draw a line to show what is in the expanded
          // area
          gc.setForeground(gray);
          int x1 = x + 1 + (outerSize / 2);
          int yTop = y + outerSize + 2;
          int yBottom = y + ((block.getSize() - 1) * lineHeight) + (outerSize / 2);
          gc.drawLine(x1, yTop, x1, yBottom);
          gc.drawLine(x1, yBottom, client.width - 1, yBottom);
          gc.setForeground(black);
        }
      }
      blockIndex++;
    }
  }