java.awt.font.TextHitInfo#getInsertionIndex ( )源码实例Demo

下面列出了java.awt.font.TextHitInfo#getInsertionIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: SwingBox   文件: TextBoxView.java
@Override
public int viewToModel(float x, float y, Shape a, Bias[] biasReturn)
{
    Rectangle alloc = toRect(a);
    // Move the y co-ord of the hit onto the baseline. This is because
    // TextLayout supports
    // italic carets and we do not.
    TextLayout layout = getTextLayout();
    TextHitInfo hit = layout.hitTestChar(x - (float) alloc.getX(), 0f);
    // TextHitInfo hit = layout.hitTestChar(x - box.getAbsoluteContentX(),
    // 0f);
    int pos = hit.getInsertionIndex();
    biasReturn[0] = hit.isLeadingEdge() ? Position.Bias.Forward
            : Position.Bias.Backward;
    return pos + getStartOffset();
}
 
源代码2 项目: jdk1.8-source-analysis   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码3 项目: dragonwell8_jdk   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码4 项目: TencentKona-8   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码5 项目: jdk8u60   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码6 项目: JDKSourceCode1.8   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码7 项目: openjdk-jdk8u   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码8 项目: netbeans   文件: HighlightsViewUtils.java
static int viewToIndex(TextLayout textLayout, double x, Shape alloc, Position.Bias[] biasReturn) {
    Rectangle2D bounds = ViewUtils.shapeAsRect(alloc);
    TextHitInfo hitInfo = x2Index(textLayout, (float)(x - bounds.getX()));
    if (biasReturn != null) {
        biasReturn[0] = hitInfo.isLeadingEdge() ? Position.Bias.Forward : Position.Bias.Backward;
    }
    return hitInfo.getInsertionIndex();
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码10 项目: Bytecoder   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码11 项目: openjdk-jdk9   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码12 项目: jdk8u-jdk   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码13 项目: consulo   文件: DesktopEditorImpl.java
private void setInputMethodCaretPosition(@Nonnull InputMethodEvent e) {
  if (composedText != null) {
    int dot = composedTextRange.getStartOffset();

    TextHitInfo caretPos = e.getCaret();
    if (caretPos != null) {
      dot += caretPos.getInsertionIndex();
    }

    getCaretModel().moveToOffset(dot);
    getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  }
}
 
源代码14 项目: hottub   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码15 项目: openjdk-8-source   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码16 项目: openjdk-8   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码17 项目: jdk8u_jdk   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
源代码18 项目: binnavi   文件: ZyCaret.java
private int calcCaretPosition(final int hitLine, final double x, final double y) {
  final ZyLineContent content = m_content.getLineContent(hitLine);

  final TextLayout textlayout = m_content.getLineContent(hitLine).getTextLayout();
  final TextHitInfo hitInfo = textlayout.hitTestChar((float) x, (float) y, content.getBounds());
  return hitInfo.getInsertionIndex();
}
 
源代码19 项目: binnavi   文件: ZyCaret.java
private int calcHitPosition(final int caretPosition, final double x, final double y,
    final double zoomFactor) {
  boolean switched = false;

  int lp = m_mouse_pressed_y;
  int lr = m_mouse_released_y;

  if (lp > lr) {
    lp = m_mouse_released_y;
    lr = m_mouse_pressed_y;

    switched = true;
  }

  final int linecount = m_content.getLineCount();
  final double height = (float) m_content.getLineHeight();

  int maxIndex = caretPosition;
  for (int line = lp; line <= lr; line++) {
    double deltaY = 0;
    if (switched) {
      deltaY = height * zoomFactor * line;
    } else {
      deltaY = -(height * zoomFactor * (linecount - line));
    }

    final TextLayout textLayout = m_content.getLineContent(line).getTextLayout();
    final TextHitInfo hitInfo =
        textLayout.hitTestChar((float) x, (float) (y + deltaY), textLayout.getBounds());
    final int insertionIndex = hitInfo.getInsertionIndex();

    if ((caretPosition < insertionIndex) && (insertionIndex > maxIndex)) {
      maxIndex = insertionIndex;
    }
  }

  return maxIndex;
}
 
源代码20 项目: jdk8u-dev-jdk   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}