protected synchronized void damage(Rectangle r) { if (r != null) { JTextComponent component = getComponent(); x = r.x; y = r.y; Font font = component.getFont(); width = component.getFontMetrics(font).charWidth('w'); height = r.height; repaint(); } } }
fm = component.getFontMetrics(font); fonts.put(key, fm);
FontMetrics fontMetrics = component.getFontMetrics(component.getFont()); Insets insets = getInsets(); int availableWidth = getSize().width - insets.left - insets.right;
@Override protected void paint(Graphics g, Rectangle rect, JTextComponent c) { g.setColor(color); FontMetrics fm = c.getFontMetrics(c.getFont()); int baseline = rect.y + rect.height - fm.getDescent() + 1; g.drawLine(rect.x, baseline, rect.x + rect.width, baseline); g.drawLine(rect.x, baseline + 1, rect.x + rect.width, baseline + 1); } }
@Override protected void paint(Graphics g, Rectangle rect, JTextComponent c) { g.setColor(color); FontMetrics fm = c.getFontMetrics(c.getFont()); int baseline = rect.y + rect.height - fm.getDescent() + 1; g.drawLine(rect.x, baseline, rect.x + rect.width, baseline); } }
protected void paint(Graphics g, Rectangle rect, JTextComponent c) { Font f = c.getFont(); FontMetrics fm = c.getFontMetrics(f); int y = rect.y - 1 + fm.getAscent(); g.setFont(f); g.setColor(color); g.drawString(symbol, rect.x, y); } }
@Override public Dimension getPreferredSize() { Dimension dim = new Dimension(); dim.height = _editor.getHeight(); FontMetrics fm = _editor.getFontMetrics( _editor.getFont() ); dim.width = fm.stringWidth( String.valueOf( dim.height / fm.getHeight() + 1 ) ); dim.width = Math.max( dim.width, GosuEditor.MIN_LINENUMBER_WIDTH ); dim.width += getLineInfoRequiredWidth(); return dim; }
public static int maxLinesVisibleInWindow(JTextComponent component) { Container container = getAncestorOfClass(JViewport.class, component); if (container == null) return 0; JViewport viewport = (JViewport)container; int extentHeight = viewport.getExtentSize().height; FontMetrics fm = component.getFontMetrics(component.getFont()); int characterHeight = fm.getHeight(); return (int)extentHeight/characterHeight - 1; }
/** * Get the closest position within the document of the component that * has given line and column. * @param editor * @param line the first being 1 * @param column the first being 1 * @return the closest positon for the text component at given line and * column */ public static int getDocumentPosition(JTextComponent editor, int line, int column) { int lineHeight = editor.getFontMetrics(editor.getFont()).getHeight(); int charWidth = editor.getFontMetrics(editor.getFont()).charWidth('m'); int y = line * lineHeight; int x = column * charWidth; Point pt = new Point(x, y); int pos = editor.viewToModel(pt); return pos; }
private static Dimension computeSizeForTextComponentColumns(JTextComponent textComponent, int columns) { Dimension size = textComponent.getPreferredSize(); Font font = textComponent.getFont(); if (font == null) { return size; } FontMetrics fontMetrics = textComponent.getFontMetrics(font); if (fontMetrics == null) { return size; } // Insets insets = textComponent.getInsets(); // int insetsWidth = insets == null ? 0 : insets.left + insets.right; size.width = columns * (fontMetrics.charWidth('a'))/* + insetsWidth*/; // NOI18N return size; }
void mouseClicked(JTextComponent c, Point p) { Point position = new Point(p); position.y += c.getFontMetrics(c.getFont()).getHeight(); SwingUtilities.convertPointToScreen(position, c); performGoToAction(position); }
protected synchronized void damage(Rectangle r) { if (r != null) { JTextComponent component = getComponent(); x = r.x; y = r.y; Font font = component.getFont(); width = component.getFontMetrics(font).charWidth('w'); height = r.height; repaint(); } } }
protected synchronized void damage(Rectangle r) { if (r != null) { JTextComponent component = getComponent(); x = r.x; y = r.y; Font font = component.getFont(); width = component.getFontMetrics(font).charWidth('w'); height = r.height; repaint(); } } }
protected synchronized void damage(Rectangle r) { if (r != null) { JTextComponent component = getComponent(); x = r.x; y = r.y; Font font = component.getFont(); width = component.getFontMetrics(font).charWidth('w'); height = r.height; repaint(); } } }
protected synchronized void damage(Rectangle r) { if (r != null) { JTextComponent component = getComponent(); x = r.x; y = r.y; Font font = component.getFont(); width = component.getFontMetrics(font).charWidth('w'); height = r.height; repaint(); } } }
protected synchronized void damage(Rectangle r) { if (r != null) { JTextComponent component = getComponent(); x = r.x; y = r.y; Font font = component.getFont(); width = component.getFontMetrics(font).charWidth('w'); height = r.height; repaint(); } } }
protected int computePrefWidth () { FontMetrics fm = command.getFontMetrics(command.getFont()); ProviderModel pModel = ProviderModel.getInstance(); int maxWidth = 0; for (Category cat : pModel.getCategories()) { // skip recent category if (CommandEvaluator.RECENT.equals(cat.getName())) { continue; } maxWidth = Math.max(maxWidth, fm.stringWidth(getHintText(cat))); } // don't allow width grow too much return Math.min(350, maxWidth); }
@Override public Dimension getPreferredSize() { Dimension dim = new Dimension(); dim.height = _editor.getHeight(); FontMetrics fm = _editor.getFontMetrics( _editor.getFont() ); int iLineHeight = fm.getHeight(); iLineHeight += getLineSpacingAttr( iLineHeight ); int iLines = getHeight() / iLineHeight; dim.width = fm.stringWidth( String.valueOf( iLines ) ); dim.width = Math.max( dim.width, GosuEditor.MIN_LINENUMBER_WIDTH ); dim.width += getLineInfoRequiredWidth(); Insets borderInsets = getBorder().getBorderInsets( this ); dim.width += borderInsets.left + borderInsets.right; return dim; }
void checkLineLimit() { BaseDocument doc = getDocument(); if (doc != null) { Integer lineLimit = (Integer) doc.getProperty(BaseDocument.LINE_LIMIT_PROP); if (lineLimit != null) { if (component != null) { // Not using FM cache - could be called too early FontMetrics fm = component.getFontMetrics(getDefaultColoring().getFont()); if (fm != null) { int charWidth = fm.stringWidth("A"); updateVirtualWidth(charWidth * lineLimit.intValue() + lineNumberWidth); } } } } }
void checkLineLimit() { BaseDocument doc = getDocument(); if (doc != null) { Integer lineLimit = (Integer)doc.getProperty(BaseDocument.LINE_LIMIT_PROP); if (lineLimit != null) { if (component != null) { // Not using FM cache - could be called too early FontMetrics fm = component.getFontMetrics(getDefaultColoring().getFont()); if (fm != null) { int charWidth = fm.stringWidth("A"); // NOI18N updateVirtualWidth(charWidth * lineLimit.intValue() + lineNumberWidth); } } } } }