Search in sources :

Example 91 with FontMetrics

use of java.awt.FontMetrics in project processdash by dtuma.

the class DataProblemsTextArea method paint.

@Override
public void paint(Graphics g) {
    super.paint(g);
    if (getText().trim().length() == 0) {
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g.setColor(hintColor);
        g.setFont(hintFont);
        Insets ins = getInsets();
        FontMetrics fm = g.getFontMetrics();
        g.drawString(hint, ins.left, ins.top + fm.getAscent());
    }
}
Also used : Insets(java.awt.Insets) FontMetrics(java.awt.FontMetrics) Graphics2D(java.awt.Graphics2D)

Example 92 with FontMetrics

use of java.awt.FontMetrics in project jdk8u_jdk by JetBrains.

the class SynthSliderUI method layout.

/**
     * Lays out the slider.
     */
protected void layout() {
    SynthContext context = getContext(slider);
    SynthGraphicsUtils synthGraphics = style.getGraphicsUtils(context);
    // Get the insets for the track.
    Insets trackInsets = new Insets(0, 0, 0, 0);
    SynthContext trackContext = getContext(slider, Region.SLIDER_TRACK);
    style.getInsets(trackContext, trackInsets);
    trackContext.dispose();
    if (slider.getOrientation() == JSlider.HORIZONTAL) {
        // Calculate the height of all the subcomponents so we can center
        // them.
        valueRect.height = 0;
        if (paintValue) {
            valueRect.height = synthGraphics.getMaximumCharHeight(context);
        }
        trackRect.height = trackHeight;
        tickRect.height = 0;
        if (slider.getPaintTicks()) {
            tickRect.height = getTickLength();
        }
        labelRect.height = 0;
        if (slider.getPaintLabels()) {
            labelRect.height = getHeightOfTallestLabel();
        }
        contentRect.height = valueRect.height + trackRect.height + trackInsets.top + trackInsets.bottom + tickRect.height + labelRect.height + 4;
        contentRect.width = slider.getWidth() - insetCache.left - insetCache.right;
        // Check if any of the labels will paint out of bounds.
        int pad = 0;
        if (slider.getPaintLabels()) {
            // Calculate the track rectangle.  It is necessary for
            // xPositionForValue to return correct values.
            trackRect.x = insetCache.left;
            trackRect.width = contentRect.width;
            Dictionary dictionary = slider.getLabelTable();
            if (dictionary != null) {
                int minValue = slider.getMinimum();
                int maxValue = slider.getMaximum();
                // Iterate through the keys in the dictionary and find the
                // first and last labels indices that fall within the
                // slider range.
                int firstLblIdx = Integer.MAX_VALUE;
                int lastLblIdx = Integer.MIN_VALUE;
                for (Enumeration keys = dictionary.keys(); keys.hasMoreElements(); ) {
                    int keyInt = ((Integer) keys.nextElement()).intValue();
                    if (keyInt >= minValue && keyInt < firstLblIdx) {
                        firstLblIdx = keyInt;
                    }
                    if (keyInt <= maxValue && keyInt > lastLblIdx) {
                        lastLblIdx = keyInt;
                    }
                }
                // Calculate the pad necessary for the labels at the first
                // and last visible indices.
                pad = getPadForLabel(firstLblIdx);
                pad = Math.max(pad, getPadForLabel(lastLblIdx));
            }
        }
        // Calculate the painting rectangles for each of the different
        // slider areas.
        valueRect.x = trackRect.x = tickRect.x = labelRect.x = (insetCache.left + pad);
        valueRect.width = trackRect.width = tickRect.width = labelRect.width = (contentRect.width - (pad * 2));
        int centerY = slider.getHeight() / 2 - contentRect.height / 2;
        valueRect.y = centerY;
        centerY += valueRect.height + 2;
        trackRect.y = centerY + trackInsets.top;
        centerY += trackRect.height + trackInsets.top + trackInsets.bottom;
        tickRect.y = centerY;
        centerY += tickRect.height + 2;
        labelRect.y = centerY;
        centerY += labelRect.height;
    } else {
        // Calculate the width of all the subcomponents so we can center
        // them.
        trackRect.width = trackHeight;
        tickRect.width = 0;
        if (slider.getPaintTicks()) {
            tickRect.width = getTickLength();
        }
        labelRect.width = 0;
        if (slider.getPaintLabels()) {
            labelRect.width = getWidthOfWidestLabel();
        }
        valueRect.y = insetCache.top;
        valueRect.height = 0;
        if (paintValue) {
            valueRect.height = synthGraphics.getMaximumCharHeight(context);
        }
        // Get the max width of the min or max value of the slider.
        FontMetrics fm = slider.getFontMetrics(slider.getFont());
        valueRect.width = Math.max(synthGraphics.computeStringWidth(context, slider.getFont(), fm, "" + slider.getMaximum()), synthGraphics.computeStringWidth(context, slider.getFont(), fm, "" + slider.getMinimum()));
        int l = valueRect.width / 2;
        int w1 = trackInsets.left + trackRect.width / 2;
        int w2 = trackRect.width / 2 + trackInsets.right + tickRect.width + labelRect.width;
        contentRect.width = Math.max(w1, l) + Math.max(w2, l) + 2 + insetCache.left + insetCache.right;
        contentRect.height = slider.getHeight() - insetCache.top - insetCache.bottom;
        // Layout the components.
        trackRect.y = tickRect.y = labelRect.y = valueRect.y + valueRect.height;
        trackRect.height = tickRect.height = labelRect.height = contentRect.height - valueRect.height;
        int startX = slider.getWidth() / 2 - contentRect.width / 2;
        if (SynthLookAndFeel.isLeftToRight(slider)) {
            if (l > w1) {
                startX += (l - w1);
            }
            trackRect.x = startX + trackInsets.left;
            startX += trackInsets.left + trackRect.width + trackInsets.right;
            tickRect.x = startX;
            labelRect.x = startX + tickRect.width + 2;
        } else {
            if (l > w2) {
                startX += (l - w2);
            }
            labelRect.x = startX;
            startX += labelRect.width + 2;
            tickRect.x = startX;
            trackRect.x = startX + tickRect.width + trackInsets.left;
        }
    }
    context.dispose();
    lastSize = slider.getSize();
}
Also used : Dictionary(java.util.Dictionary) Insets(java.awt.Insets) Enumeration(java.util.Enumeration) FontMetrics(java.awt.FontMetrics) Point(java.awt.Point)

Example 93 with FontMetrics

use of java.awt.FontMetrics in project jdk8u_jdk by JetBrains.

the class SynthSliderUI method paint.

/**
     * Paints the specified component.
     *
     * @param context context for the component being painted
     * @param g the {@code Graphics} object used for painting
     * @see #update(Graphics,JComponent)
     */
protected void paint(SynthContext context, Graphics g) {
    recalculateIfInsetsChanged();
    recalculateIfOrientationChanged();
    Rectangle clip = g.getClipBounds();
    if (lastSize == null || !lastSize.equals(slider.getSize())) {
        calculateGeometry();
    }
    if (paintValue) {
        FontMetrics fm = SwingUtilities2.getFontMetrics(slider, g);
        int labelWidth = context.getStyle().getGraphicsUtils(context).computeStringWidth(context, g.getFont(), fm, "" + slider.getValue());
        valueRect.x = thumbRect.x + (thumbRect.width - labelWidth) / 2;
        // outside slider bounds.
        if (slider.getOrientation() == JSlider.HORIZONTAL) {
            if (valueRect.x + labelWidth > insetCache.left + contentRect.width) {
                valueRect.x = (insetCache.left + contentRect.width) - labelWidth;
            }
            valueRect.x = Math.max(valueRect.x, 0);
        }
        g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
        context.getStyle().getGraphicsUtils(context).paintText(context, g, "" + slider.getValue(), valueRect.x, valueRect.y, -1);
    }
    if (slider.getPaintTrack() && clip.intersects(trackRect)) {
        SynthContext subcontext = getContext(slider, Region.SLIDER_TRACK);
        paintTrack(subcontext, g, trackRect);
        subcontext.dispose();
    }
    if (clip.intersects(thumbRect)) {
        SynthContext subcontext = getContext(slider, Region.SLIDER_THUMB);
        paintThumb(subcontext, g, thumbRect);
        subcontext.dispose();
    }
    if (slider.getPaintTicks() && clip.intersects(tickRect)) {
        paintTicks(g);
    }
    if (slider.getPaintLabels() && clip.intersects(labelRect)) {
        paintLabels(g);
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) Point(java.awt.Point)

Example 94 with FontMetrics

use of java.awt.FontMetrics in project chipKIT32-MAX by chipKIT32.

the class CompositionTextPainter method refillComposedArea.

/**
   * Fill color to erase characters drawn by original TextAreaPainter. 
   *  
   * @param fillColor fill color to erase characters drawn by original TextAreaPainter method.
   * @param x x-coordinate where to fill.
   * @param y y-coordinate where to fill.
   */
private void refillComposedArea(Color fillColor, int x, int y) {
    Graphics gfx = textArea.getPainter().getGraphics();
    gfx.setColor(fillColor);
    FontMetrics fm = textArea.getPainter().getFontMetrics();
    int newY = y - (fm.getHeight() - CompositionTextManager.COMPOSING_UNDERBAR_HEIGHT);
    int paintHeight = fm.getHeight();
    int paintWidth = (int) composedTextLayout.getBounds().getWidth();
    gfx.fillRect(x, newY, paintWidth, paintHeight);
}
Also used : Graphics(java.awt.Graphics) FontMetrics(java.awt.FontMetrics) Point(java.awt.Point)

Example 95 with FontMetrics

use of java.awt.FontMetrics in project chipKIT32-MAX by chipKIT32.

the class CompositionTextPainter method getCaretLocation.

private Point getCaretLocation() {
    Point loc = new Point();
    TextAreaPainter painter = textArea.getPainter();
    FontMetrics fm = painter.getFontMetrics();
    int offsetY = fm.getHeight() - CompositionTextManager.COMPOSING_UNDERBAR_HEIGHT;
    int lineIndex = textArea.getCaretLine();
    loc.y = lineIndex * fm.getHeight() + offsetY;
    int offsetX = composedBeginCaretPosition - textArea.getLineStartOffset(lineIndex);
    loc.x = textArea.offsetToX(lineIndex, offsetX);
    return loc;
}
Also used : TextAreaPainter(processing.app.syntax.TextAreaPainter) FontMetrics(java.awt.FontMetrics) Point(java.awt.Point) Point(java.awt.Point)

Aggregations

FontMetrics (java.awt.FontMetrics)179 Font (java.awt.Font)61 Graphics2D (java.awt.Graphics2D)35 Point (java.awt.Point)34 Dimension (java.awt.Dimension)29 Color (java.awt.Color)23 Rectangle (java.awt.Rectangle)21 Rectangle2D (java.awt.geom.Rectangle2D)21 Insets (java.awt.Insets)20 Graphics (java.awt.Graphics)16 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)14 GradientPaint (java.awt.GradientPaint)14 MPart (gov.sandia.n2a.eqset.MPart)13 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)12 Paint (java.awt.Paint)10 JTree (javax.swing.JTree)10 BasicStroke (java.awt.BasicStroke)9 BufferedImage (java.awt.image.BufferedImage)9 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)8 JLabel (javax.swing.JLabel)8