Java Code Examples for javax.swing.plaf.basic.BasicHTML#getHTMLBaseline()
The following examples show how to use
javax.swing.plaf.basic.BasicHTML#getHTMLBaseline() .
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: SeaGlassLabelUI.java From seaglass with Apache License 2.0 | 5 votes |
public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException("Width and height must be >= 0"); } JLabel label = (JLabel) c; String text = label.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = label.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SeaGlassContext context = getContext(label); FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context)); context.getStyle().getGraphicsUtils(context).layoutText(context, fm, label.getText(), label.getIcon(), label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(), label.getVerticalTextPosition(), viewRect, iconRect, textRect, label.getIconTextGap()); View view = (View) label.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } context.dispose(); return baseline; }
Example 2
Source File: DarkTabbedPaneUIBridge.java From darklaf with MIT License | 5 votes |
/** * Returns the baseline for the specified tab. * * @param tab index of tab to get baseline for * @return baseline or a value < 0 indicating there is no reasonable baseline * @throws IndexOutOfBoundsException if index is out of range (index < 0 || index >= tab count) * @since 1.6 */ protected int getBaseline(final int tab) { if (tabPane.getTabComponentAt(tab) != null) { int offset = getBaselineOffset(); if (offset != 0) { // The offset is not applied to the tab component, and so // in general we can't get good alignment like with components // in the tab. return -1; } Component c = tabPane.getTabComponentAt(tab); Dimension pref = c.getPreferredSize(); Insets tabInsets = getTabInsets(tabPane.getTabPlacement(), tab); int cellHeight = maxTabHeight - tabInsets.top - tabInsets.bottom; return c.getBaseline(pref.width, pref.height) + (cellHeight - pref.height) / 2 + tabInsets.top; } else { View view = getTextViewForTab(tab); if (view != null) { int viewHeight = (int) view.getPreferredSpan(View.Y_AXIS); int baseline = BasicHTML.getHTMLBaseline(view, (int) view.getPreferredSpan(View.X_AXIS), viewHeight); if (baseline >= 0) { return maxTabHeight / 2 - viewHeight / 2 + baseline + getBaselineOffset(); } return -1; } } FontMetrics metrics = getFontMetrics(); int fontHeight = metrics.getHeight(); int fontBaseline = metrics.getAscent(); return maxTabHeight / 2 - fontHeight / 2 + fontBaseline + getBaselineOffset(); }
Example 3
Source File: SynthButtonUI.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } AbstractButton b = (AbstractButton)c; String text = b.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = b.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SynthContext context = getContext(b); FontMetrics fm = context.getComponent().getFontMetrics( context.getStyle().getFont(context)); context.getStyle().getGraphicsUtils(context).layoutText( context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); View view = (View)b.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } context.dispose(); return baseline; }
Example 4
Source File: SeaGlassButtonUI.java From seaglass with Apache License 2.0 | 4 votes |
/** * @see javax.swing.plaf.basic.BasicButtonUI#getBaseline(javax.swing.JComponent, * int, int) */ public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException("Width and height must be >= 0"); } AbstractButton b = (AbstractButton) c; String text = b.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = b.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SeaGlassContext context = getContext(b); FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context)); context.getStyle().getGraphicsUtils(context).layoutText(context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); View view = (View) b.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } context.dispose(); return baseline; }
Example 5
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 6
Source File: MetalToolTipUI.java From openjdk-jdk9 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 7
Source File: SynthButtonUI.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } AbstractButton b = (AbstractButton)c; String text = b.getText(); if (text == null || text.isEmpty()) { return -1; } Insets i = b.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SynthContext context = getContext(b); SynthStyle style; if (context.getStyle() != null) { style = context.getStyle(); } else { style = SynthLookAndFeel.updateStyle(context, this); } FontMetrics fm = context.getComponent().getFontMetrics( style.getFont(context)); style.getGraphicsUtils(context).layoutText( context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); View view = (View)b.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } return baseline; }
Example 8
Source File: MetalToolTipUI.java From Bytecoder with Apache License 2.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.isEmpty()) { g.setFont(smallFont); g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); SwingUtilities2.drawString(tip, g, accelString, tip.getWidth() - 1 - insets.right - accelSpacing + padSpaceBetweenStrings - 3, paintTextR.y + accelBL); } }
Example 9
Source File: SynthButtonUI.java From Java8CN with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } AbstractButton b = (AbstractButton)c; String text = b.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = b.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SynthContext context = getContext(b); FontMetrics fm = context.getComponent().getFontMetrics( context.getStyle().getFont(context)); context.getStyle().getGraphicsUtils(context).layoutText( context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); View view = (View)b.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } context.dispose(); return baseline; }
Example 10
Source File: MetalToolTipUI.java From openjdk-jdk8u-backup 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 11
Source File: SynthButtonUI.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } AbstractButton b = (AbstractButton)c; String text = b.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = b.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SynthContext context = getContext(b); FontMetrics fm = context.getComponent().getFontMetrics( context.getStyle().getFont(context)); context.getStyle().getGraphicsUtils(context).layoutText( context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); View view = (View)b.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } context.dispose(); return baseline; }
Example 12
Source File: MetalToolTipUI.java From openjdk-jdk8u 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: MetalToolTipUI.java From JDKSourceCode1.8 with MIT License | 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 14
Source File: MetalToolTipUI.java From jdk8u-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 15
Source File: SynthButtonUI.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } AbstractButton b = (AbstractButton)c; String text = b.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = b.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SynthContext context = getContext(b); FontMetrics fm = context.getComponent().getFontMetrics( context.getStyle().getFont(context)); context.getStyle().getGraphicsUtils(context).layoutText( context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); View view = (View)b.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } context.dispose(); return baseline; }
Example 16
Source File: SynthButtonUI.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } AbstractButton b = (AbstractButton)c; String text = b.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = b.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SynthContext context = getContext(b); FontMetrics fm = context.getComponent().getFontMetrics( context.getStyle().getFont(context)); context.getStyle().getGraphicsUtils(context).layoutText( context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); View view = (View)b.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } context.dispose(); return baseline; }
Example 17
Source File: MetalToolTipUI.java From Java8CN with Apache License 2.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 18
Source File: MetalToolTipUI.java From dragonwell8_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 19
Source File: SynthButtonUI.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public int getBaseline(JComponent c, int width, int height) { if (c == null) { throw new NullPointerException("Component must be non-null"); } if (width < 0 || height < 0) { throw new IllegalArgumentException( "Width and height must be >= 0"); } AbstractButton b = (AbstractButton)c; String text = b.getText(); if (text == null || "".equals(text)) { return -1; } Insets i = b.getInsets(); Rectangle viewRect = new Rectangle(); Rectangle textRect = new Rectangle(); Rectangle iconRect = new Rectangle(); viewRect.x = i.left; viewRect.y = i.top; viewRect.width = width - (i.right + viewRect.x); viewRect.height = height - (i.bottom + viewRect.y); // layout the text and icon SynthContext context = getContext(b); FontMetrics fm = context.getComponent().getFontMetrics( context.getStyle().getFont(context)); context.getStyle().getGraphicsUtils(context).layoutText( context, fm, b.getText(), b.getIcon(), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); View view = (View)b.getClientProperty(BasicHTML.propertyKey); int baseline; if (view != null) { baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height); if (baseline >= 0) { baseline += textRect.y; } } else { baseline = textRect.y + fm.getAscent(); } context.dispose(); return baseline; }
Example 20
Source File: MetalToolTipUI.java From jdk1.8-source-analysis with Apache License 2.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); } }