Java Code Examples for sun.swing.SwingUtilities2#getFontMetrics()
The following examples show how to use
sun.swing.SwingUtilities2#getFontMetrics() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetalToggleButtonUI.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); FontMetrics fm = SwingUtilities2.getFontMetrics(b, g); int mnemIndex = b.getDisplayedMnemonicIndex(); /* Draw the Text */ if(model.isEnabled()) { /*** paint the text normally */ g.setColor(b.getForeground()); } else { /*** paint the text disabled ***/ if (model.isSelected()) { g.setColor(c.getBackground()); } else { g.setColor(getDisabledTextColor()); } } SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent()); }
Example 2
Source File: SeaGlassTabbedPaneUI.java From seaglass with Apache License 2.0 | 6 votes |
/** * Paint the label text for a tab. * * @param ss the SynthContext. * @param g the Graphics context. * @param tabPlacement the side the tabs are on. * @param font the font to use. * @param metrics the font metrics. * @param tabIndex the index of the tab to lay out. * @param title the text for the label, if any. * @param textRect Rectangle to place text in * @param isSelected is the tab selected? */ protected void paintText(SeaGlassContext ss, Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) { g.setFont(font); View v = getTextViewForTab(tabIndex); if (v != null) { // html v.paint(g, textRect); } else { // plain text int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex); FontMetrics fm = SwingUtilities2.getFontMetrics(tabPane, g); title = SwingUtilities2.clipStringIfNecessary(tabPane, fm, title, textRect.width); g.setColor(ss.getStyle().getColor(ss, ColorType.TEXT_FOREGROUND)); ss.getStyle().getGraphicsUtils(ss).paintText(ss, g, title, textRect, mnemIndex); } }
Example 3
Source File: BasicProgressBarUI.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Designate the place where the progress string will be painted. * This implementation places it at the center of the progress * bar (in both x and y). Override this if you want to right, * left, top, or bottom align the progress string or if you need * to nudge it around for any reason. */ protected Point getStringPlacement(Graphics g, String progressString, int x,int y,int width,int height) { FontMetrics fontSizer = SwingUtilities2.getFontMetrics(progressBar, g, progressBar.getFont()); int stringWidth = SwingUtilities2.stringWidth(progressBar, fontSizer, progressString); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { return new Point(x + Math.round(width/2 - stringWidth/2), y + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent()) / 2)); } else { // VERTICAL return new Point(x + ((width - fontSizer.getAscent() + fontSizer.getLeading() + fontSizer.getDescent()) / 2), y + Math.round(height/2 - stringWidth/2)); } }
Example 4
Source File: BasicProgressBarUI.java From Java8CN with Apache License 2.0 | 6 votes |
/** * Designate the place where the progress string will be painted. * This implementation places it at the center of the progress * bar (in both x and y). Override this if you want to right, * left, top, or bottom align the progress string or if you need * to nudge it around for any reason. */ protected Point getStringPlacement(Graphics g, String progressString, int x,int y,int width,int height) { FontMetrics fontSizer = SwingUtilities2.getFontMetrics(progressBar, g, progressBar.getFont()); int stringWidth = SwingUtilities2.stringWidth(progressBar, fontSizer, progressString); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { return new Point(x + Math.round(width/2 - stringWidth/2), y + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent()) / 2)); } else { // VERTICAL return new Point(x + ((width - fontSizer.getAscent() + fontSizer.getLeading() + fontSizer.getDescent()) / 2), y + Math.round(height/2 - stringWidth/2)); } }
Example 5
Source File: BasicButtonUI.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * As of Java 2 platform v 1.4 this method should not be used or overriden. * Use the paintText method which takes the AbstractButton argument. */ protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); int mnemonicIndex = b.getDisplayedMnemonicIndex(); /* Draw the Text */ if(model.isEnabled()) { /*** paint the text normally */ g.setColor(b.getForeground()); SwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset()); } else { /*** paint the text disabled ***/ g.setColor(b.getBackground().brighter()); SwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent()); g.setColor(b.getBackground().darker()); SwingUtilities2.drawStringUnderlineCharAt(c, g,text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1); } }
Example 6
Source File: BasicMercuryIconTrackerUI.java From MercuryTrade with MIT License | 6 votes |
protected Point getStringPlacement(Graphics g, String progressString, int x, int y, int width, int height) { FontMetrics fontSizer = SwingUtilities2.getFontMetrics(tracker, g, tracker.getFont()); int stringWidth = SwingUtilities2.stringWidth(tracker, fontSizer, progressString); if (descriptor.getOrientation() == AdrComponentOrientation.HORIZONTAL) { return new Point(x + Math.round(width / 2 - stringWidth / 2), y + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent()) / 2)); } else { return new Point(x + ((width - fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent()) / 2), y + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent()) / 2)); } }
Example 7
Source File: StyleSheet.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Draws the letter or number for an ordered list. * * @param g the graphics context * @param letter type of ordered list to draw * @param ax x coordinate to place the bullet * @param ay y coordinate to place the bullet * @param aw width of the container the bullet is placed in * @param ah height of the container the bullet is placed in * @param index position of the list item in the list */ void drawLetter(Graphics g, char letter, int ax, int ay, int aw, int ah, float align, int index) { String str = formatItemNum(index, letter); str = isLeftToRight ? str + "." : "." + str; FontMetrics fm = SwingUtilities2.getFontMetrics(null, g); int stringwidth = SwingUtilities2.stringWidth(null, fm, str); int gap = isLeftToRight ? - (stringwidth + bulletgap) : (aw + bulletgap); int x = ax + gap; int y = Math.max(ay + fm.getAscent(), ay + (int)(ah * align)); SwingUtilities2.drawString(null, g, str, x, y); }
Example 8
Source File: BasicToolTipUI.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public void paint(Graphics g, JComponent c) { Font font = c.getFont(); FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g, font); Dimension size = c.getSize(); g.setColor(c.getForeground()); // fix for bug 4153892 String tipText = ((JToolTip)c).getTipText(); if (tipText == null) { tipText = ""; } Insets insets = c.getInsets(); Rectangle paintTextR = new Rectangle( insets.left + 3, insets.top, size.width - (insets.left + insets.right) - 6, size.height - (insets.top + insets.bottom)); View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, paintTextR); } else { g.setFont(font); SwingUtilities2.drawString(c, g, tipText, paintTextR.x, paintTextR.y + metrics.getAscent()); } }
Example 9
Source File: DarculaCheckBoxUI.java From consulo with Apache License 2.0 | 5 votes |
@SuppressWarnings("NonSynchronizedMethodOverridesSynchronizedMethod") @Override public void paint(Graphics g2d, JComponent c) { Graphics2D g = (Graphics2D)g2d; Dimension size = c.getSize(); AbstractButton b = (AbstractButton)c; Rectangle viewRect = updateViewRect(b, new Rectangle(size)); Rectangle iconRect = new Rectangle(); Rectangle textRect = new Rectangle(); Font f = c.getFont(); g.setFont(f); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f); String text = SwingUtilities .layoutCompoundLabel(c, fm, b.getText(), getDefaultIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); if (c.isOpaque()) { g.setColor(b.getBackground()); g.fillRect(0, 0, size.width, size.height); } drawCheckIcon(c, g, b, iconRect, b.isSelected(), b.isEnabled()); drawText(c, g, b, fm, textRect, text); }
Example 10
Source File: BasicLabelUI.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Paints the label text with the foreground color, if the label is opaque * then paints the entire background with the background color. The Label * text is drawn by {@link #paintEnabledText} or {@link #paintDisabledText}. * The locations of the label parts are computed by {@link #layoutCL}. * * @see #paintEnabledText * @see #paintDisabledText * @see #layoutCL */ public void paint(Graphics g, JComponent c) { JLabel label = (JLabel)c; String text = label.getText(); Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); if ((icon == null) && (text == null)) { return; } FontMetrics fm = SwingUtilities2.getFontMetrics(label, g); String clippedText = layout(label, fm, c.getWidth(), c.getHeight()); if (icon != null) { icon.paintIcon(c, g, paintIconR.x, paintIconR.y); } if (text != null) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, paintTextR); } else { int textX = paintTextR.x; int textY = paintTextR.y + fm.getAscent(); if (label.isEnabled()) { paintEnabledText(label, g, clippedText, textX, textY); } else { paintDisabledText(label, g, clippedText, textX, textY); } } } }
Example 11
Source File: BasicRadioButtonUI.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * paint the radio button */ public synchronized void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); Font f = c.getFont(); g.setFont(f); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, f); Insets i = c.getInsets(); size = b.getSize(size); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = size.width - (i.right + viewRect.x); viewRect.height = size.height - (i.bottom + viewRect.y); iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0; textRect.x = textRect.y = textRect.width = textRect.height = 0; Icon altIcon = b.getIcon(); Icon selectedIcon = null; Icon disabledIcon = null; String text = SwingUtilities.layoutCompoundLabel( c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getText() == null ? 0 : b.getIconTextGap()); // fill background if(c.isOpaque()) { g.setColor(b.getBackground()); g.fillRect(0,0, size.width, size.height); } // Paint the radio button if(altIcon != null) { if(!model.isEnabled()) { if(model.isSelected()) { altIcon = b.getDisabledSelectedIcon(); } else { altIcon = b.getDisabledIcon(); } } else if(model.isPressed() && model.isArmed()) { altIcon = b.getPressedIcon(); if(altIcon == null) { // Use selected icon altIcon = b.getSelectedIcon(); } } else if(model.isSelected()) { if(b.isRolloverEnabled() && model.isRollover()) { altIcon = b.getRolloverSelectedIcon(); if (altIcon == null) { altIcon = b.getSelectedIcon(); } } else { altIcon = b.getSelectedIcon(); } } else if(b.isRolloverEnabled() && model.isRollover()) { altIcon = b.getRolloverIcon(); } if(altIcon == null) { altIcon = b.getIcon(); } altIcon.paintIcon(c, g, iconRect.x, iconRect.y); } else { getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y); } // Draw the Text if(text != null) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, textRect); } else { paintText(g, b, textRect, text); } if(b.hasFocus() && b.isFocusPainted() && textRect.width > 0 && textRect.height > 0 ) { paintFocus(g, textRect, size); } } }
Example 12
Source File: MetalToolTipUI.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
public void paint(Graphics g, JComponent c) { JToolTip tip = (JToolTip)c; Font font = c.getFont(); FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g, font); Dimension size = c.getSize(); int accelBL; g.setColor(c.getForeground()); // fix for bug 4153892 String tipText = tip.getTipText(); if (tipText == null) { tipText = ""; } String accelString = getAcceleratorString(tip); FontMetrics accelMetrics = SwingUtilities2.getFontMetrics(c, g, smallFont); int accelSpacing = calcAccelSpacing(c, accelMetrics, accelString); Insets insets = tip.getInsets(); Rectangle paintTextR = new Rectangle( insets.left + 3, insets.top, size.width - (insets.left + insets.right) - 6 - accelSpacing, size.height - (insets.top + insets.bottom)); View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, paintTextR); accelBL = BasicHTML.getHTMLBaseline(v, paintTextR.width, paintTextR.height); } else { g.setFont(font); SwingUtilities2.drawString(tip, g, tipText, paintTextR.x, paintTextR.y + metrics.getAscent()); accelBL = metrics.getAscent(); } if (!accelString.equals("")) { g.setFont(smallFont); g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); SwingUtilities2.drawString(tip, g, accelString, tip.getWidth() - 1 - insets.right - accelSpacing + padSpaceBetweenStrings - 3, paintTextR.y + accelBL); } }
Example 13
Source File: DefaultPreviewPanel.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private int paintText(Graphics g, int offsetX) { g.setFont(getFont()); JComponent host = getColorChooser(); if (host == null) { host = this; } FontMetrics fm = SwingUtilities2.getFontMetrics(host, g); int ascent = fm.getAscent(); int height = fm.getHeight(); int width = SwingUtilities2.stringWidth(host, fm, getSampleText()); int textXOffset = offsetX + textGap; Color color = getForeground(); g.setColor(color); SwingUtilities2.drawString(host, g, getSampleText(),textXOffset+(textGap/2), ascent+2); g.fillRect(textXOffset, ( height) + textGap, width + (textGap), height +2); g.setColor(Color.black); SwingUtilities2.drawString(host, g, getSampleText(), textXOffset+(textGap/2), height+ascent+textGap+2); g.setColor(Color.white); g.fillRect(textXOffset, ( height + textGap) * 2, width + (textGap), height +2); g.setColor(color); SwingUtilities2.drawString(host, g, getSampleText(), textXOffset+(textGap/2), ((height+textGap) * 2)+ascent+2); return width + textGap*3; }
Example 14
Source File: MetalToolTipUI.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public void paint(Graphics g, JComponent c) { JToolTip tip = (JToolTip)c; Font font = c.getFont(); FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g, font); Dimension size = c.getSize(); int accelBL; g.setColor(c.getForeground()); // fix for bug 4153892 String tipText = tip.getTipText(); if (tipText == null) { tipText = ""; } String accelString = getAcceleratorString(tip); FontMetrics accelMetrics = SwingUtilities2.getFontMetrics(c, g, smallFont); int accelSpacing = calcAccelSpacing(c, accelMetrics, accelString); Insets insets = tip.getInsets(); Rectangle paintTextR = new Rectangle( insets.left + 3, insets.top, size.width - (insets.left + insets.right) - 6 - accelSpacing, size.height - (insets.top + insets.bottom)); View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, paintTextR); accelBL = BasicHTML.getHTMLBaseline(v, paintTextR.width, paintTextR.height); } else { g.setFont(font); SwingUtilities2.drawString(tip, g, tipText, paintTextR.x, paintTextR.y + metrics.getAscent()); accelBL = metrics.getAscent(); } if (!accelString.equals("")) { g.setFont(smallFont); g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); SwingUtilities2.drawString(tip, g, accelString, tip.getWidth() - 1 - insets.right - accelSpacing + padSpaceBetweenStrings - 3, paintTextR.y + accelBL); } }
Example 15
Source File: SynthTabbedPaneUI.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void paintTab(SynthContext ss, Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) { Rectangle tabRect = rects[tabIndex]; int selectedIndex = tabPane.getSelectedIndex(); boolean isSelected = selectedIndex == tabIndex; updateTabContext(tabIndex, isSelected, isSelected && selectedTabIsPressed, (getRolloverTab() == tabIndex), (getFocusIndex() == tabIndex)); SynthLookAndFeel.updateSubregion(ss, g, tabRect); int x = tabRect.x; int y = tabRect.y; int height = tabRect.height; int width = tabRect.width; int placement = tabPane.getTabPlacement(); if (extendTabsToBase && runCount > 1) { //paint this tab such that its edge closest to the base is equal to //edge of the selected tab closest to the base. In terms of the TOP //tab placement, this will cause the bottom of each tab to be //painted even with the bottom of the selected tab. This is because //in each tab placement (TOP, LEFT, BOTTOM, RIGHT) the selected tab //is closest to the base. if (selectedIndex >= 0) { Rectangle r = rects[selectedIndex]; switch (placement) { case TOP: int bottomY = r.y + r.height; height = bottomY - tabRect.y; break; case LEFT: int rightX = r.x + r.width; width = rightX - tabRect.x; break; case BOTTOM: int topY = r.y; height = (tabRect.y + tabRect.height) - topY; y = topY; break; case RIGHT: int leftX = r.x; width = (tabRect.x + tabRect.width) - leftX; x = leftX; break; } } } tabContext.getPainter().paintTabbedPaneTabBackground(tabContext, g, x, y, width, height, tabIndex, placement); tabContext.getPainter().paintTabbedPaneTabBorder(tabContext, g, x, y, width, height, tabIndex, placement); if (tabPane.getTabComponentAt(tabIndex) == null) { String title = tabPane.getTitleAt(tabIndex); Font font = ss.getStyle().getFont(ss); FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font); Icon icon = getIconForTab(tabIndex); layoutLabel(ss, tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected); paintText(ss, g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected); paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected); } }
Example 16
Source File: SynthInternalFrameTitlePane.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
protected void paint(SynthContext context, Graphics g) { String title = frame.getTitle(); if (title != null) { SynthStyle style = context.getStyle(); g.setColor(style.getColor(context, ColorType.TEXT_FOREGROUND)); g.setFont(style.getFont(context)); // Center text vertically. FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g); int baseline = (getHeight() + fm.getAscent() - fm.getLeading() - fm.getDescent()) / 2; JButton lastButton = null; if (frame.isIconifiable()) { lastButton = iconButton; } else if (frame.isMaximizable()) { lastButton = maxButton; } else if (frame.isClosable()) { lastButton = closeButton; } int maxX; int minX; boolean ltr = SynthLookAndFeel.isLeftToRight(frame); int titleAlignment = this.titleAlignment; if (ltr) { if (lastButton != null) { maxX = lastButton.getX() - titleSpacing; } else { maxX = frame.getWidth() - frame.getInsets().right - titleSpacing; } minX = menuButton.getX() + menuButton.getWidth() + titleSpacing; } else { if (lastButton != null) { minX = lastButton.getX() + lastButton.getWidth() + titleSpacing; } else { minX = frame.getInsets().left + titleSpacing; } maxX = menuButton.getX() - titleSpacing; if (titleAlignment == SwingConstants.LEADING) { titleAlignment = SwingConstants.TRAILING; } else if (titleAlignment == SwingConstants.TRAILING) { titleAlignment = SwingConstants.LEADING; } } String clippedTitle = getTitle(title, fm, maxX - minX); if (clippedTitle == title) { // String fit, align as necessary. if (titleAlignment == SwingConstants.TRAILING) { minX = maxX - style.getGraphicsUtils(context). computeStringWidth(context, g.getFont(), fm, title); } else if (titleAlignment == SwingConstants.CENTER) { int width = style.getGraphicsUtils(context). computeStringWidth(context, g.getFont(), fm, title); minX = Math.max(minX, (getWidth() - width) / 2); minX = Math.min(maxX - width, minX); } } style.getGraphicsUtils(context).paintText( context, g, clippedTitle, minX, baseline - fm.getAscent(), -1); } }
Example 17
Source File: WindowsInternalFrameTitlePane.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void paintComponent(Graphics g) { XPStyle xp = XPStyle.getXP(); paintTitleBackground(g); String title = frame.getTitle(); if (title != null) { boolean isSelected = frame.isSelected(); Font oldFont = g.getFont(); Font newFont = (titleFont != null) ? titleFont : getFont(); g.setFont(newFont); // Center text vertically. FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g, newFont); int baseline = (getHeight() + fm.getAscent() - fm.getLeading() - fm.getDescent()) / 2; Rectangle lastIconBounds = new Rectangle(0, 0, 0, 0); if (frame.isIconifiable()) { lastIconBounds = iconButton.getBounds(); } else if (frame.isMaximizable()) { lastIconBounds = maxButton.getBounds(); } else if (frame.isClosable()) { lastIconBounds = closeButton.getBounds(); } int titleX; int titleW; int gap = 2; if (WindowsGraphicsUtils.isLeftToRight(frame)) { if (lastIconBounds.x == 0) { // There are no icons lastIconBounds.x = frame.getWidth() - frame.getInsets().right; } titleX = systemLabel.getX() + systemLabel.getWidth() + gap; if (xp != null) { titleX += 2; } titleW = lastIconBounds.x - titleX - gap; } else { if (lastIconBounds.x == 0) { // There are no icons lastIconBounds.x = frame.getInsets().left; } titleW = SwingUtilities2.stringWidth(frame, fm, title); int minTitleX = lastIconBounds.x + lastIconBounds.width + gap; if (xp != null) { minTitleX += 2; } int availableWidth = systemLabel.getX() - gap - minTitleX; if (availableWidth > titleW) { titleX = systemLabel.getX() - gap - titleW; } else { titleX = minTitleX; titleW = availableWidth; } } title = getTitle(frame.getTitle(), fm, titleW); if (xp != null) { String shadowType = null; if (isSelected) { shadowType = xp.getString(this, Part.WP_CAPTION, State.ACTIVE, Prop.TEXTSHADOWTYPE); } if ("single".equalsIgnoreCase(shadowType)) { Point shadowOffset = xp.getPoint(this, Part.WP_WINDOW, State.ACTIVE, Prop.TEXTSHADOWOFFSET); Color shadowColor = xp.getColor(this, Part.WP_WINDOW, State.ACTIVE, Prop.TEXTSHADOWCOLOR, null); if (shadowOffset != null && shadowColor != null) { g.setColor(shadowColor); SwingUtilities2.drawString(frame, g, title, titleX + shadowOffset.x, baseline + shadowOffset.y); } } } g.setColor(isSelected ? selectedTextColor : notSelectedTextColor); SwingUtilities2.drawString(frame, g, title, titleX, baseline); g.setFont(oldFont); } }
Example 18
Source File: SynthGraphicsUtils.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Paints an icon and text. This will render the text as html, if * necessary, and offset the location by the insets of the component. * * @param ss SynthContext * @param g Graphics to render string and icon into * @param text Text to layout * @param icon Icon to layout * @param hAlign horizontal alignment * @param vAlign vertical alignment * @param hTextPosition horizontal text position * @param vTextPosition vertical text position * @param iconTextGap gap between icon and text * @param mnemonicIndex Index into text to render the mnemonic at, -1 * indicates no mnemonic. * @param textOffset Amount to offset the text when painting */ public void paintText(SynthContext ss, Graphics g, String text, Icon icon, int hAlign, int vAlign, int hTextPosition, int vTextPosition, int iconTextGap, int mnemonicIndex, int textOffset) { if ((icon == null) && (text == null)) { return; } JComponent c = ss.getComponent(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); Insets insets = SynthLookAndFeel.getPaintingInsets(ss, paintInsets); paintViewR.x = insets.left; paintViewR.y = insets.top; paintViewR.width = c.getWidth() - (insets.left + insets.right); paintViewR.height = c.getHeight() - (insets.top + insets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; String clippedText = layoutText(ss, fm, text, icon, hAlign, vAlign, hTextPosition, vTextPosition, paintViewR, paintIconR, paintTextR, iconTextGap); if (icon != null) { Color color = g.getColor(); if (ss.getStyle().getBoolean(ss, "TableHeader.alignSorterArrow", false) && "TableHeader.renderer".equals(c.getName())) { paintIconR.x = paintViewR.width - paintIconR.width; } else { paintIconR.x += textOffset; } paintIconR.y += textOffset; SynthIcon.paintIcon(icon, ss, g, paintIconR.x, paintIconR.y, paintIconR.width, paintIconR.height); g.setColor(color); } if (text != null) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, paintTextR); } else { paintTextR.x += textOffset; paintTextR.y += textOffset; paintText(ss, g, clippedText, paintTextR, mnemonicIndex); } } }
Example 19
Source File: SynthGraphicsUtils.java From jdk8u-jdk with GNU General Public License v2.0 | 3 votes |
/** * Paints text at the specified location. This will not attempt to * render the text as html nor will it offset by the insets of the * component. * * @param ss SynthContext * @param g Graphics used to render string in. * @param text Text to render * @param x X location to draw text at. * @param y Upper left corner to draw text at. * @param mnemonicIndex Index to draw string at. */ public void paintText(SynthContext ss, Graphics g, String text, int x, int y, int mnemonicIndex) { if (text != null) { JComponent c = ss.getComponent(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); y += fm.getAscent(); SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemonicIndex, x, y); } }
Example 20
Source File: SynthGraphicsUtils.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Paints text at the specified location. This will not attempt to * render the text as html nor will it offset by the insets of the * component. * * @param ss SynthContext * @param g Graphics used to render string in. * @param text Text to render * @param x X location to draw text at. * @param y Upper left corner to draw text at. * @param mnemonicIndex Index to draw string at. */ public void paintText(SynthContext ss, Graphics g, String text, int x, int y, int mnemonicIndex) { if (text != null) { JComponent c = ss.getComponent(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); y += fm.getAscent(); SwingUtilities2.drawStringUnderlineCharAt(c, g, text, mnemonicIndex, x, y); } }