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());
}
}
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();
}
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);
}
}
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);
}
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;
}
Aggregations