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); }
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; }
@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(); }
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()); }
@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(); }
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)); }
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; }
public int viewToModel(final Point p, final Position.Bias[] biasRet) { return ((BasicTextUI)ui).viewToModel(JTextComponent.this, p, biasRet); }
public Rectangle modelToView(final int pos, final Position.Bias bias) throws BadLocationException { return ((BasicTextUI)ui).modelToView(JTextComponent.this, pos, bias); }
public String getToolTipText(final MouseEvent me) { String toolTipText = super.getToolTipText(); return (toolTipText != null) ? toolTipText : ((BasicTextUI) ui).getToolTipText(this, new Point(me.getX(), me.getY())); }
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()); }