Java 类javax.swing.plaf.basic.BasicTextUI 实例源码

项目:cn1    文件:NavigationFilter.java   
public int getNextVisualPositionFrom(final JTextComponent c, final int pos,
        final Position.Bias bias, final int direction, final Position.Bias[] biasRet)
        throws BadLocationException {
    if (c == null)
        return 0;
    BasicTextUI ui = (BasicTextUI)c.getUI();
    View rootView = ui.getRootView(c);
    Rectangle rect = c.getVisibleRect();
    if (rect == null)
        return 0;
    Insets insets = c.getInsets();
    rect.x += insets.left;
    rect.y += insets.top;
    rect.width -= insets.left + insets.right;
    rect.height -= insets.top + insets.bottom;
    return rootView.getNextVisualPositionFrom(pos,bias,rect,direction, biasRet);
}
项目:cn1    文件:JTextComponent.java   
public Rectangle getCharacterBounds(final int i) {
    Rectangle forward = null;
    Rectangle backward = null;
    try {
        forward = ((BasicTextUI) ui).modelToView(JTextComponent.this, i,
                Position.Bias.Forward);
        backward = ((BasicTextUI) ui).modelToView(JTextComponent.this,
                Math.min(document.getLength(), i + 1),
                Position.Bias.Backward);
    } catch (final BadLocationException e) {
    }
    if (forward == null || backward == null) {
        return null;
    }
    forward.width = Math.abs(forward.x - backward.x) + 1;
    forward.x = Math.min(forward.x, backward.x);
    return forward;
}
项目:cn1    文件:PasswordViewTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    bWasException = false;
    length = content.length();
    jf = new JFrame();
    pf = new JPasswordField(content);
    view = (PasswordView) ((BasicTextUI) pf.getUI()).getRootView(pf).getView(0);
    fm = pf.getFontMetrics(pf.getFont());
    assertNotNull(fm);
    text = new Segment();
    pf.getDocument().getText(0, length, text);
    echoChars = new Segment(new char[] { '*', '*', '*', '*', '*', '*', '*', '*' }, 0,
            length);
    textWidth = Utilities.getTabbedTextWidth(text, fm, 0, view, 0);
    echoCharsWidth = Utilities.getTabbedTextWidth(echoChars, fm, 0, view, 0);
    height = fm.getHeight();
    assertNotNull(text);
    jf.getContentPane().add(pf);
    pf.setForeground(Color.RED);
    pf.setSelectedTextColor(Color.GREEN);
    jf.setSize(200, 300);
    jf.pack();
}
项目:cn1    文件:JTextComponent_byAuxiliaryComponentTest.java   
public void testJTextComponent() {
    jtComp = new JTextComp();
    assertNotNull(jtComp);
    assertTrue(jtComp.getUI() instanceof TextCompUI);
    assertTrue(jtComp.getCaret() instanceof BasicTextUI.BasicCaret);
    assertEquals("Dot=(0, Forward) Mark=(0, Forward)", jtComp.getCaret().toString());
    assertTrue(jtComp.getHighlighter() instanceof BasicTextUI.BasicHighlighter);
    assertEquals(ComponentOrientation.UNKNOWN, jtComp.getComponentOrientation());
    assertTrue(jtComp.isEditable());
    assertFalse(jtComp.getDragEnabled());
    assertEquals('\0', jtComp.getFocusAccelerator());
    assertEquals("TextCompUI", jtComp.getKeymap().getName());
    assertEquals(0, jtComp.getKeymap().getBoundActions().length);
    assertEquals(0, jtComp.getKeymap().getBoundKeyStrokes().length);
    assertEquals(new InsetsUIResource(0, 0, 0, 0), jtComp.getMargin());
}
项目:freeVM    文件:NavigationFilter.java   
public int getNextVisualPositionFrom(final JTextComponent c, final int pos,
        final Position.Bias bias, final int direction, final Position.Bias[] biasRet)
        throws BadLocationException {
    if (c == null)
        return 0;
    BasicTextUI ui = (BasicTextUI)c.getUI();
    View rootView = ui.getRootView(c);
    Rectangle rect = c.getVisibleRect();
    if (rect == null)
        return 0;
    Insets insets = c.getInsets();
    rect.x += insets.left;
    rect.y += insets.top;
    rect.width -= insets.left + insets.right;
    rect.height -= insets.top + insets.bottom;
    return rootView.getNextVisualPositionFrom(pos,bias,rect,direction, biasRet);
}
项目:freeVM    文件:JTextComponent.java   
public Rectangle getCharacterBounds(final int i) {
    Rectangle forward = null;
    Rectangle backward = null;
    try {
        forward = ((BasicTextUI) ui).modelToView(JTextComponent.this, i,
                Position.Bias.Forward);
        backward = ((BasicTextUI) ui).modelToView(JTextComponent.this,
                Math.min(document.getLength(), i + 1),
                Position.Bias.Backward);
    } catch (final BadLocationException e) {
    }
    if (forward == null || backward == null) {
        return null;
    }
    forward.width = Math.abs(forward.x - backward.x) + 1;
    forward.x = Math.min(forward.x, backward.x);
    return forward;
}
项目:freeVM    文件:PasswordViewTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    bWasException = false;
    length = content.length();
    jf = new JFrame();
    pf = new JPasswordField(content);
    view = (PasswordView) ((BasicTextUI) pf.getUI()).getRootView(pf).getView(0);
    fm = pf.getFontMetrics(pf.getFont());
    assertNotNull(fm);
    text = new Segment();
    pf.getDocument().getText(0, length, text);
    echoChars = new Segment(new char[] { '*', '*', '*', '*', '*', '*', '*', '*' }, 0,
            length);
    textWidth = Utilities.getTabbedTextWidth(text, fm, 0, view, 0);
    echoCharsWidth = Utilities.getTabbedTextWidth(echoChars, fm, 0, view, 0);
    height = fm.getHeight();
    assertNotNull(text);
    jf.getContentPane().add(pf);
    pf.setForeground(Color.RED);
    pf.setSelectedTextColor(Color.GREEN);
    jf.setSize(200, 300);
    jf.pack();
}
项目:freeVM    文件:JTextComponent_byAuxiliaryComponentTest.java   
public void testJTextComponent() {
    jtComp = new JTextComp();
    assertNotNull(jtComp);
    assertTrue(jtComp.getUI() instanceof TextCompUI);
    assertTrue(jtComp.getCaret() instanceof BasicTextUI.BasicCaret);
    assertEquals("Dot=(0, Forward) Mark=(0, Forward)", jtComp.getCaret().toString());
    assertTrue(jtComp.getHighlighter() instanceof BasicTextUI.BasicHighlighter);
    assertEquals(ComponentOrientation.UNKNOWN, jtComp.getComponentOrientation());
    assertTrue(jtComp.isEditable());
    assertFalse(jtComp.getDragEnabled());
    assertEquals('\0', jtComp.getFocusAccelerator());
    assertEquals("TextCompUI", jtComp.getKeymap().getName());
    assertEquals(0, jtComp.getKeymap().getBoundActions().length);
    assertEquals(0, jtComp.getKeymap().getBoundKeyStrokes().length);
    assertEquals(new InsetsUIResource(0, 0, 0, 0), jtComp.getMargin());
}
项目:freeVM    文件:NavigationFilter.java   
public int getNextVisualPositionFrom(final JTextComponent c, final int pos,
        final Position.Bias bias, final int direction, final Position.Bias[] biasRet)
        throws BadLocationException {
    if (c == null)
        return 0;
    BasicTextUI ui = (BasicTextUI)c.getUI();
    View rootView = ui.getRootView(c);
    Rectangle rect = c.getVisibleRect();
    if (rect == null)
        return 0;
    Insets insets = c.getInsets();
    rect.x += insets.left;
    rect.y += insets.top;
    rect.width -= insets.left + insets.right;
    rect.height -= insets.top + insets.bottom;
    return rootView.getNextVisualPositionFrom(pos,bias,rect,direction, biasRet);
}
项目:freeVM    文件:JTextComponent.java   
public Rectangle getCharacterBounds(final int i) {
    Rectangle forward = null;
    Rectangle backward = null;
    try {
        forward = ((BasicTextUI) ui).modelToView(JTextComponent.this, i,
                Position.Bias.Forward);
        backward = ((BasicTextUI) ui).modelToView(JTextComponent.this,
                Math.min(document.getLength(), i + 1),
                Position.Bias.Backward);
    } catch (final BadLocationException e) {
    }
    if (forward == null || backward == null) {
        return null;
    }
    forward.width = Math.abs(forward.x - backward.x) + 1;
    forward.x = Math.min(forward.x, backward.x);
    return forward;
}
项目:freeVM    文件:PasswordViewTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    bWasException = false;
    length = content.length();
    jf = new JFrame();
    pf = new JPasswordField(content);
    view = (PasswordView) ((BasicTextUI) pf.getUI()).getRootView(pf).getView(0);
    fm = pf.getFontMetrics(pf.getFont());
    assertNotNull(fm);
    text = new Segment();
    pf.getDocument().getText(0, length, text);
    echoChars = new Segment(new char[] { '*', '*', '*', '*', '*', '*', '*', '*' }, 0,
            length);
    textWidth = Utilities.getTabbedTextWidth(text, fm, 0, view, 0);
    echoCharsWidth = Utilities.getTabbedTextWidth(echoChars, fm, 0, view, 0);
    height = fm.getHeight();
    assertNotNull(text);
    jf.getContentPane().add(pf);
    pf.setForeground(Color.RED);
    pf.setSelectedTextColor(Color.GREEN);
    jf.setSize(200, 300);
    jf.pack();
}
项目:freeVM    文件:JTextComponent_byAuxiliaryComponentTest.java   
public void testJTextComponent() {
    jtComp = new JTextComp();
    assertNotNull(jtComp);
    assertTrue(jtComp.getUI() instanceof TextCompUI);
    assertTrue(jtComp.getCaret() instanceof BasicTextUI.BasicCaret);
    assertEquals("Dot=(0, Forward) Mark=(0, Forward)", jtComp.getCaret().toString());
    assertTrue(jtComp.getHighlighter() instanceof BasicTextUI.BasicHighlighter);
    assertEquals(ComponentOrientation.UNKNOWN, jtComp.getComponentOrientation());
    assertTrue(jtComp.isEditable());
    assertFalse(jtComp.getDragEnabled());
    assertEquals('\0', jtComp.getFocusAccelerator());
    assertEquals("TextCompUI", jtComp.getKeymap().getName());
    assertEquals(0, jtComp.getKeymap().getBoundActions().length);
    assertEquals(0, jtComp.getKeymap().getBoundKeyStrokes().length);
    assertEquals(new InsetsUIResource(0, 0, 0, 0), jtComp.getMargin());
}
项目:cn1    文件:FieldViewTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    jf = new JFrame();
    jtf = new JTextField("JTextField for FieldView testing");
    jf.getContentPane().add(jtf);
    fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf).getView(0);
    jf.setSize(200, 100);
    jf.pack();
}
项目:cn1    文件:FieldViewTest.java   
public void testGetPreferredSpan() {
    FontMetrics fm = fv.getFontMetrics();
    assertEquals(fm.getHeight(), (int) fv.getPreferredSpan(View.Y_AXIS));
    assertEquals(fm.stringWidth(jtf.getText()), (int) fv.getPreferredSpan(View.X_AXIS));
    jtf.setFont(new java.awt.Font("SimSun", 0, 12));
    fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf).getView(0);
    fm = jtf.getFontMetrics(jtf.getFont());
    assertEquals(fm.stringWidth(jtf.getText()), (int) fv.getPreferredSpan(View.X_AXIS));
}
项目:freeVM    文件:FieldViewTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    jf = new JFrame();
    jtf = new JTextField("JTextField for FieldView testing");
    jf.getContentPane().add(jtf);
    fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf).getView(0);
    jf.setSize(200, 100);
    jf.pack();
}
项目:freeVM    文件:FieldViewTest.java   
public void testGetPreferredSpan() {
    FontMetrics fm = fv.getFontMetrics();
    assertEquals(fm.getHeight(), (int) fv.getPreferredSpan(View.Y_AXIS));
    assertEquals(fm.stringWidth(jtf.getText()), (int) fv.getPreferredSpan(View.X_AXIS));
    jtf.setFont(new java.awt.Font("SimSun", 0, 12));
    fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf).getView(0);
    fm = jtf.getFontMetrics(jtf.getFont());
    assertEquals(fm.stringWidth(jtf.getText()), (int) fv.getPreferredSpan(View.X_AXIS));
}
项目:freeVM    文件:FieldViewTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    jf = new JFrame();
    jtf = new JTextField("JTextField for FieldView testing");
    jf.getContentPane().add(jtf);
    fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf).getView(0);
    jf.setSize(200, 100);
    jf.pack();
}
项目:freeVM    文件:FieldViewTest.java   
public void testGetPreferredSpan() {
    FontMetrics fm = fv.getFontMetrics();
    assertEquals(fm.getHeight(), (int) fv.getPreferredSpan(View.Y_AXIS));
    assertEquals(fm.stringWidth(jtf.getText()), (int) fv.getPreferredSpan(View.X_AXIS));
    jtf.setFont(new java.awt.Font("SimSun", 0, 12));
    fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf).getView(0);
    fm = jtf.getFontMetrics(jtf.getFont());
    assertEquals(fm.stringWidth(jtf.getText()), (int) fv.getPreferredSpan(View.X_AXIS));
}
项目:thingweb-gui    文件:ThingPanelUI.java   
protected JComponent getXsd(JsonNode type, boolean editable) {
    DocumentFilter filter = null;

    if(type != null && type.getNodeType() == JsonNodeType.STRING) {
        switch (type.asText()) {
        case "xsd:unsignedLong":
            filter = new IntegerRangeDocumentFilter(BigInteger.ZERO, MAX_UNSIGNED_LONG);
            break;
        case "xsd:unsignedInt":
            filter = new IntegerRangeDocumentFilter(BigInteger.ZERO, MAX_UNSIGNED_INT);
            break;
        case "xsd:unsignedShort":
            filter = new IntegerRangeDocumentFilter(BigInteger.ZERO, MAX_UNSIGNED_SHORT);
            break;
        case "xsd:unsignedByte":
            filter = new IntegerRangeDocumentFilter(BigInteger.ZERO, MAX_UNSIGNED_BYTE);
            break;
        case "xsd:long":
            filter = new IntegerRangeDocumentFilter(MIN_LONG, MAX_LONG);
            break;
        case "xsd:int":
            filter = new IntegerRangeDocumentFilter(MIN_INT, MAX_INT);
            break;
        case "xsd:short":
            filter = new IntegerRangeDocumentFilter(MIN_SHORT, MAX_SHORT);
            break;
        case "xsd:byte":
            filter = new IntegerRangeDocumentFilter(MIN_BYTE, MAX_BYTE);
            break;
        case "xsd:boolean":
            filter = new BooleanDocumentFilter();
            break;
        }
    }


    JTextField XsdComponent = new JTextField();

    JTextComponent textComponent = (JTextComponent) XsdComponent;
    textComponent.setEditable(editable);
    if(type != null) {
        BasicTextUI textFieldUI = new HintTextFieldUI(" " + type, editable, Color.GRAY);
        textComponent.setUI(textFieldUI);
        textComponent.setToolTipText(type.toString());
    }


    if (filter == null) {
        log.warn("TextField created without input control for type: " + type);
    } else {
        PlainDocument pd = (PlainDocument) textComponent.getDocument();
        pd.setDocumentFilter(filter);
        log.info("TextField created with input control for type: " + type + ", " + filter);
    }

    return XsdComponent;
}
项目:cn1    文件:JTextComponent.java   
public int viewToModel(final Point p, final Position.Bias[] biasRet) {
    return ((BasicTextUI)ui).viewToModel(JTextComponent.this,
                                         p, biasRet);
}
项目:cn1    文件:JTextComponent.java   
public Rectangle modelToView(final int pos, final Position.Bias bias)
    throws BadLocationException {
    return ((BasicTextUI)ui).modelToView(JTextComponent.this,
                                         pos, bias);
}
项目:cn1    文件:JTextComponent.java   
public String getToolTipText(final MouseEvent me) {
    String toolTipText = super.getToolTipText();
    return (toolTipText != null) ? toolTipText
            : ((BasicTextUI) ui).getToolTipText(this, new Point(me.getX(),
                    me.getY()));
}
项目:cn1    文件:FieldViewTest.java   
public void testGetFontMetrics() {
    assertEquals(jtf.getFontMetrics(jtf.getFont()), fv.getFontMetrics());
    jtf.setFont(new java.awt.Font("SimSun", 0, 12));
    fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf).getView(0);
    assertEquals(jtf.getFontMetrics(jtf.getFont()), fv.getFontMetrics());
}
项目:freeVM    文件:JTextComponent.java   
public int viewToModel(final Point p, final Position.Bias[] biasRet) {
    return ((BasicTextUI)ui).viewToModel(JTextComponent.this,
                                         p, biasRet);
}
项目:freeVM    文件:JTextComponent.java   
public Rectangle modelToView(final int pos, final Position.Bias bias)
    throws BadLocationException {
    return ((BasicTextUI)ui).modelToView(JTextComponent.this,
                                         pos, bias);
}
项目:freeVM    文件:JTextComponent.java   
public String getToolTipText(final MouseEvent me) {
    String toolTipText = super.getToolTipText();
    return (toolTipText != null) ? toolTipText
            : ((BasicTextUI) ui).getToolTipText(this, new Point(me.getX(),
                    me.getY()));
}
项目:freeVM    文件:FieldViewTest.java   
public void testGetFontMetrics() {
    assertEquals(jtf.getFontMetrics(jtf.getFont()), fv.getFontMetrics());
    jtf.setFont(new java.awt.Font("SimSun", 0, 12));
    fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf).getView(0);
    assertEquals(jtf.getFontMetrics(jtf.getFont()), fv.getFontMetrics());
}
项目:freeVM    文件:JTextComponent.java   
public int viewToModel(final Point p, final Position.Bias[] biasRet) {
    return ((BasicTextUI)ui).viewToModel(JTextComponent.this,
                                         p, biasRet);
}
项目:freeVM    文件:JTextComponent.java   
public Rectangle modelToView(final int pos, final Position.Bias bias)
    throws BadLocationException {
    return ((BasicTextUI)ui).modelToView(JTextComponent.this,
                                         pos, bias);
}
项目:freeVM    文件:JTextComponent.java   
public String getToolTipText(final MouseEvent me) {
    String toolTipText = super.getToolTipText();
    return (toolTipText != null) ? toolTipText
            : ((BasicTextUI) ui).getToolTipText(this, new Point(me.getX(),
                    me.getY()));
}
项目:freeVM    文件:FieldViewTest.java   
public void testGetFontMetrics() {
    assertEquals(jtf.getFontMetrics(jtf.getFont()), fv.getFontMetrics());
    jtf.setFont(new java.awt.Font("SimSun", 0, 12));
    fv = (FieldView) ((BasicTextUI) jtf.getUI()).getRootView(jtf).getView(0);
    assertEquals(jtf.getFontMetrics(jtf.getFont()), fv.getFontMetrics());
}