Java Code Examples for sun.swing.SwingUtilities2#drawString()

The following examples show how to use sun.swing.SwingUtilities2#drawString() . 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: MotifDesktopIconUI.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void paint(Graphics g) {
    super.paint(g);

    // touch-up frame
    int maxX = getWidth() - 1;
    Color shadow =
        UIManager.getColor("inactiveCaptionBorder").darker().darker();
    g.setColor(shadow);
    g.setClip(0, 0, getWidth(), getHeight());
    g.drawLine(maxX - 1, 1, maxX - 1, 1);
    g.drawLine(maxX, 0, maxX, 0);

    // fill background
    g.setColor(UIManager.getColor("inactiveCaption"));
    g.fillRect(2, 1, maxX - 3, LABEL_HEIGHT + 1);

    // draw text -- clipping to truncate text like CDE/Motif
    g.setClip(2, 1, maxX - 4, LABEL_HEIGHT);
    int y = LABEL_HEIGHT - SwingUtilities2.getFontMetrics(frame, g).
                                           getDescent();
    g.setColor(UIManager.getColor("inactiveCaptionText"));
    String title = frame.getTitle();
    if (title != null) {
        SwingUtilities2.drawString(frame, g, title, 4, y);
    }
}
 
Example 2
Source File: MotifDesktopIconUI.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public void paint(Graphics g) {
    super.paint(g);

    // touch-up frame
    int maxX = getWidth() - 1;
    Color shadow =
        UIManager.getColor("inactiveCaptionBorder").darker().darker();
    g.setColor(shadow);
    g.setClip(0, 0, getWidth(), getHeight());
    g.drawLine(maxX - 1, 1, maxX - 1, 1);
    g.drawLine(maxX, 0, maxX, 0);

    // fill background
    g.setColor(UIManager.getColor("inactiveCaption"));
    g.fillRect(2, 1, maxX - 3, LABEL_HEIGHT + 1);

    // draw text -- clipping to truncate text like CDE/Motif
    g.setClip(2, 1, maxX - 4, LABEL_HEIGHT);
    int y = LABEL_HEIGHT - SwingUtilities2.getFontMetrics(frame, g).
                                           getDescent();
    g.setColor(UIManager.getColor("inactiveCaptionText"));
    String title = frame.getTitle();
    if (title != null) {
        SwingUtilities2.drawString(frame, g, title, 4, y);
    }
}
 
Example 3
Source File: Metacity.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected void drawTitle(Node node, Graphics g, JInternalFrame jif) {
    NamedNodeMap attrs = node.getAttributes();
    String colorStr = getStringAttr(attrs, "color");
    int i = colorStr.indexOf("gtk:fg[");
    if (i > 0) {
        colorStr = colorStr.substring(0, i) + "gtk:text[" + colorStr.substring(i+7);
    }
    Color color = parseColor(colorStr);
    int x = aee.evaluate(getStringAttr(attrs, "x"));
    int y = aee.evaluate(getStringAttr(attrs, "y"));

    String title = jif.getTitle();
    if (title != null) {
        FontMetrics fm = SwingUtilities2.getFontMetrics(jif, g);
        title = SwingUtilities2.clipStringIfNecessary(jif, fm, title,
                     calculateTitleArea(jif).width);
        g.setColor(color);
        SwingUtilities2.drawString(jif, g, title, x, y + fm.getAscent());
    }
}
 
Example 4
Source File: AquaProgressBarUI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected void paintString(final Graphics g, final int x, final int y, final int width, final int height) {
    if (!(g instanceof Graphics2D)) return;

    final Graphics2D g2 = (Graphics2D)g;
    final String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    final Point renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
    final Rectangle oldClip = g2.getClipBounds();

    if (isHorizontal()) {
        g2.setColor(selectionForeground);
        SwingUtilities2.drawString(progressBar, g2, progressString, renderLocation.x, renderLocation.y);
    } else { // VERTICAL
        // We rotate it -90 degrees, then translate it down since we are going to be bottom up.
        final AffineTransform savedAT = g2.getTransform();
        g2.transform(AffineTransform.getRotateInstance(0.0f - (Math.PI / 2.0f), 0, 0));
        g2.translate(-progressBar.getHeight(), 0);

        // 0,0 is now the bottom left of the viewable area, so we just draw our image at
        // the render location since that calculation knows about rotation.
        g2.setColor(selectionForeground);
        SwingUtilities2.drawString(progressBar, g2, progressString, renderLocation.x, renderLocation.y);

        g2.setTransform(savedAT);
    }

    g2.setClip(oldClip);
}
 
Example 5
Source File: StyleSheet.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: AquaUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void paintDropShadowText(final Graphics g, final JComponent c, final Font font, final FontMetrics metrics, final int x, final int y, final int offsetX, final int offsetY, final Color textColor, final Color shadowColor, final String text) {
    g.setFont(font);
    g.setColor(shadowColor);
    SwingUtilities2.drawString(c, g, text, x + offsetX, y + offsetY + metrics.getAscent());
    g.setColor(textColor);
    SwingUtilities2.drawString(c, g, text, x, y + metrics.getAscent());
}
 
Example 7
Source File: BasicToolTipUI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: BasicInternalFrameTitlePane.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
public void paintComponent(Graphics g)  {
    paintTitleBackground(g);

    if(frame.getTitle() != null) {
        boolean isSelected = frame.isSelected();
        Font f = g.getFont();
        g.setFont(getFont());
        if(isSelected)
            g.setColor(selectedTextColor);
        else
            g.setColor(notSelectedTextColor);

        // Center text vertically.
        FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
        int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
                fm.getDescent()) / 2;

        int titleX;
        Rectangle r = new Rectangle(0, 0, 0, 0);
        if (frame.isIconifiable())  r = iconButton.getBounds();
        else if (frame.isMaximizable())  r = maxButton.getBounds();
        else if (frame.isClosable())  r = closeButton.getBounds();
        int titleW;

        String title = frame.getTitle();
        if( BasicGraphicsUtils.isLeftToRight(frame) ) {
          if (r.x == 0)  r.x = frame.getWidth()-frame.getInsets().right;
          titleX = menuBar.getX() + menuBar.getWidth() + 2;
          titleW = r.x - titleX - 3;
          title = getTitle(frame.getTitle(), fm, titleW);
        } else {
            titleX = menuBar.getX() - 2
                     - SwingUtilities2.stringWidth(frame,fm,title);
        }

        SwingUtilities2.drawString(frame, g, title, titleX, baseline);
        g.setFont(f);
    }
}
 
Example 9
Source File: BasicInternalFrameTitlePane.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void paintComponent(Graphics g)  {
    paintTitleBackground(g);

    if(frame.getTitle() != null) {
        boolean isSelected = frame.isSelected();
        Font f = g.getFont();
        g.setFont(getFont());
        if(isSelected)
            g.setColor(selectedTextColor);
        else
            g.setColor(notSelectedTextColor);

        // Center text vertically.
        FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
        int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
                fm.getDescent()) / 2;

        int titleX;
        Rectangle r = new Rectangle(0, 0, 0, 0);
        if (frame.isIconifiable())  r = iconButton.getBounds();
        else if (frame.isMaximizable())  r = maxButton.getBounds();
        else if (frame.isClosable())  r = closeButton.getBounds();
        int titleW;

        String title = frame.getTitle();
        if( BasicGraphicsUtils.isLeftToRight(frame) ) {
          if (r.x == 0)  r.x = frame.getWidth()-frame.getInsets().right;
          titleX = menuBar.getX() + menuBar.getWidth() + 2;
          titleW = r.x - titleX - 3;
          title = getTitle(frame.getTitle(), fm, titleW);
        } else {
            titleX = menuBar.getX() - 2
                     - SwingUtilities2.stringWidth(frame,fm,title);
        }

        SwingUtilities2.drawString(frame, g, title, titleX, baseline);
        g.setFont(f);
    }
}
 
Example 10
Source File: AquaInternalFrameDockIconUI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void paint(final Graphics g) {
    final int width = getWidth();
    final int height = getHeight();

    final Font font = getFont();
    final FontMetrics metrics = getFontMetrics(font);
    g.setFont(font);

    final String text = getText().trim();
    final int ascent = metrics.getAscent();

    final Rectangle2D stringBounds = metrics.getStringBounds(text, g);
    final int halfway = width / 2;

    final int x = (halfway - (int)stringBounds.getWidth() / 2);

    final Graphics2D g2d = g instanceof Graphics2D ? (Graphics2D)g : null;
    if (g2d != null) {
        g.setColor(UIManager.getColor("DesktopIcon.labelBackground"));
        final Object origAA = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        final int roundHeight = height - ROUND_ADDITIONAL_HEIGHT + 1;
        g.fillRoundRect(0, 0, width, roundHeight, roundHeight, roundHeight);

        final int[] xpts = { halfway, halfway + NUB_HEIGHT, halfway - NUB_HEIGHT };
        final int[] ypts = { height, height - NUB_HEIGHT, height - NUB_HEIGHT };
        g.fillPolygon(xpts, ypts, 3);

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, origAA);
    }

    g.setColor(Color.black);
    SwingUtilities2.drawString(this, g, text, x, 2 + ascent);
    g.setColor(Color.white);
    SwingUtilities2.drawString(this, g, text, x, 1 + ascent);
}
 
Example 11
Source File: StyleSheet.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 12
Source File: BasicMercuryIconTrackerUI.java    From MercuryTrade with MIT License 5 votes vote down vote up
protected void paintString(Graphics g, int x, int y, int width, int height, int amountFull) {

        if (descriptor.isTextEnable() && tracker.isStringPainted()) {
            float value = tracker.getValue() / 1000f;

            Graphics2D g2 = this.prepareAdapter(g);
            DecimalFormat decimalFormat = new DecimalFormat(descriptor.getTextFormat());
            String progressString = String.valueOf(decimalFormat.format(value));
            if (descriptor.isCustomTextEnable()) {
                progressString = String.valueOf(descriptor.getCustomText());
            }
            g2.setFont(tracker.getFont());
            Point renderLocation = getStringPlacement(g2, progressString,
                    x, y, width, height);
            g2.setColor(this.getColorByValue());
            SwingUtilities2.drawString(tracker, g2, progressString,
                    renderLocation.x, renderLocation.y);
            if (this.descriptor.getOutlineThickness() > 0) {
                FontRenderContext frc = g2.getFontRenderContext();
                TextLayout textTl = new TextLayout(progressString, tracker.getFont(), frc);
                Shape outline = textTl.getOutline(null);
                g2.translate(renderLocation.x, renderLocation.y);
                Stroke oldStroke = g2.getStroke();
                g2.setStroke(new BasicStroke(this.descriptor.getOutlineThickness()));
                Color oldColor = g2.getColor();
                g2.setColor(this.descriptor.getOutlineColor());
                g2.draw(outline);
                g2.setColor(oldColor);
                g2.setStroke(oldStroke);
            }
        }
    }
 
Example 13
Source File: DefaultPreviewPanel.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
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: MotifBorders.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paints the border for the specified component with the
 * specified position and size.
 * @param c the component for which this border is being painted
 * @param g the paint graphics
 * @param x the x position of the painted border
 * @param y the y position of the painted border
 * @param width the width of the painted border
 * @param height the height of the painted border
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if (!(c instanceof JPopupMenu)) {
        return;
    }

    Font origFont = g.getFont();
    Color origColor = g.getColor();
    JPopupMenu popup = (JPopupMenu)c;

    String title = popup.getLabel();
    if (title == null) {
        return;
    }

    g.setFont(font);

    FontMetrics fm = SwingUtilities2.getFontMetrics(popup, g, font);
    int         fontHeight = fm.getHeight();
    int         descent = fm.getDescent();
    int         ascent = fm.getAscent();
    Point       textLoc = new Point();
    int         stringWidth = SwingUtilities2.stringWidth(popup, fm,
                                                          title);

    textLoc.y = y + ascent + TEXT_SPACING;
    textLoc.x = x + ((width - stringWidth) / 2);

    g.setColor(background);
    g.fillRect(textLoc.x - TEXT_SPACING, textLoc.y - (fontHeight-descent),
               stringWidth + (2 * TEXT_SPACING), fontHeight - descent);
    g.setColor(foreground);
    SwingUtilities2.drawString(popup, g, title, textLoc.x, textLoc.y);

    MotifGraphicsUtils.drawGroove(g, x, textLoc.y + TEXT_SPACING,
                                  width, GROOVE_HEIGHT,
                                  shadowColor, highlightColor);

    g.setFont(origFont);
    g.setColor(origColor);
}
 
Example 15
Source File: Utilities.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Paints the composed text in a GlyphView
 */
static void paintComposedText(Graphics g, Rectangle alloc, GlyphView v) {
    if (g instanceof Graphics2D) {
        Graphics2D g2d = (Graphics2D) g;
        int p0 = v.getStartOffset();
        int p1 = v.getEndOffset();
        AttributeSet attrSet = v.getElement().getAttributes();
        AttributedString as =
            (AttributedString)attrSet.getAttribute(StyleConstants.ComposedTextAttribute);
        int start = v.getElement().getStartOffset();
        int y = alloc.y + alloc.height - (int)v.getGlyphPainter().getDescent(v);
        int x = alloc.x;

        //Add text attributes
        as.addAttribute(TextAttribute.FONT, v.getFont());
        as.addAttribute(TextAttribute.FOREGROUND, v.getForeground());
        if (StyleConstants.isBold(v.getAttributes())) {
            as.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
        }
        if (StyleConstants.isItalic(v.getAttributes())) {
            as.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
        }
        if (v.isUnderline()) {
            as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
        }
        if (v.isStrikeThrough()) {
            as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
        }
        if (v.isSuperscript()) {
            as.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
        }
        if (v.isSubscript()) {
            as.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);
        }

        // draw
        AttributedCharacterIterator aci = as.getIterator(null, p0 - start, p1 - start);
        SwingUtilities2.drawString(getJComponent(v),
                                   g2d,aci,x,y);
    }
}
 
Example 16
Source File: MaterialTitlePaneUI.java    From material-ui-swing with MIT License 4 votes vote down vote up
protected void paintComponent(Graphics g) {
    if (getFrame() != null) {
        setState(getFrame().getExtendedState());
    }
    JRootPane rootPane = getRootPane();
    Window window = getWindow();
    boolean leftToRight = (window == null) ?
            rootPane.getComponentOrientation().isLeftToRight() :
            window.getComponentOrientation().isLeftToRight();
    boolean isSelected = (window == null) ? true : window.isActive();
    int width = getWidth();
    int height = getHeight();

    Color background;
    Color foreground;
    Color darkShadow;

    if (isSelected) {
        background = myActiveBackground;
        foreground = myActiveForeground;
        darkShadow = myActiveShadow;
    } else {
        background = myInactiveBackground;
        foreground = myInactiveForeground;
        darkShadow = myInactiveShadow;
    }

    g.setColor(background);
    g.fillRect(0, 0, width, height);

    g.setColor(darkShadow);
    g.drawLine(0, height - 1, width, height - 1);
    g.drawLine(0, 0, 0, 0);
    g.drawLine(width - 1, 0, width - 1, 0);

    int xOffset = leftToRight ? 5 : width - 5;

    if (getWindowDecorationStyle() == JRootPane.FRAME) {
        xOffset += leftToRight ? IMAGE_WIDTH + 5 : -IMAGE_WIDTH - 5;
    }

    String theTitle = getTitle();
    if (theTitle != null) {
        FontMetrics fm = SwingUtilities2.getFontMetrics(rootPane, g);

        g.setColor(foreground);

        int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent();

        Rectangle rect = new Rectangle(0, 0, 0, 0);
        if (myIconifyButton != null && myIconifyButton.getParent() != null) {
            rect = myIconifyButton.getBounds();
        }
        int titleW;

        if (leftToRight) {
            if (rect.x == 0) {
                rect.x = window.getWidth() - window.getInsets().right - 2;
            }
            titleW = rect.x - xOffset - 4;
            theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW);
        } else {
            titleW = xOffset - rect.x - rect.width - 4;
            theTitle = SwingUtilities2.clipStringIfNecessary(rootPane, fm, theTitle, titleW);
            xOffset -= SwingUtilities2.stringWidth(rootPane, fm, theTitle);
        }
        int titleLength = SwingUtilities2.stringWidth(rootPane, fm, theTitle);
        SwingUtilities2.drawString(rootPane, g, theTitle, xOffset, yOffset);
        xOffset += leftToRight ? titleLength + 5 : -5;
    }
}
 
Example 17
Source File: MetalToolTipUI.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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: MetalTitlePane.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Renders the TitlePane.
 */
public void paintComponent(Graphics g)  {
    // As state isn't bound, we need a convenience place to check
    // if it has changed. Changing the state typically changes the
    if (getFrame() != null) {
        setState(getFrame().getExtendedState());
    }
    JRootPane rootPane = getRootPane();
    Window window = getWindow();
    boolean leftToRight = (window == null) ?
                           rootPane.getComponentOrientation().isLeftToRight() :
                           window.getComponentOrientation().isLeftToRight();
    boolean isSelected = (window == null) ? true : window.isActive();
    int width = getWidth();
    int height = getHeight();

    Color background;
    Color foreground;
    Color darkShadow;

    MetalBumps bumps;

    if (isSelected) {
        background = activeBackground;
        foreground = activeForeground;
        darkShadow = activeShadow;
        bumps = activeBumps;
    } else {
        background = inactiveBackground;
        foreground = inactiveForeground;
        darkShadow = inactiveShadow;
        bumps = inactiveBumps;
    }

    g.setColor(background);
    g.fillRect(0, 0, width, height);

    g.setColor( darkShadow );
    g.drawLine ( 0, height - 1, width, height -1);
    g.drawLine ( 0, 0, 0 ,0);
    g.drawLine ( width - 1, 0 , width -1, 0);

    int xOffset = leftToRight ? 5 : width - 5;

    if (getWindowDecorationStyle() == JRootPane.FRAME) {
        xOffset += leftToRight ? IMAGE_WIDTH + 5 : - IMAGE_WIDTH - 5;
    }

    String theTitle = getTitle();
    if (theTitle != null) {
        FontMetrics fm = SwingUtilities2.getFontMetrics(rootPane, g);

        g.setColor(foreground);

        int yOffset = ( (height - fm.getHeight() ) / 2 ) + fm.getAscent();

        Rectangle rect = new Rectangle(0, 0, 0, 0);
        if (iconifyButton != null && iconifyButton.getParent() != null) {
            rect = iconifyButton.getBounds();
        }
        int titleW;

        if( leftToRight ) {
            if (rect.x == 0) {
                rect.x = window.getWidth() - window.getInsets().right-2;
            }
            titleW = rect.x - xOffset - 4;
            theTitle = SwingUtilities2.clipStringIfNecessary(
                            rootPane, fm, theTitle, titleW);
        } else {
            titleW = xOffset - rect.x - rect.width - 4;
            theTitle = SwingUtilities2.clipStringIfNecessary(
                            rootPane, fm, theTitle, titleW);
            xOffset -= SwingUtilities2.stringWidth(rootPane, fm,
                                                   theTitle);
        }
        int titleLength = SwingUtilities2.stringWidth(rootPane, fm,
                                                      theTitle);
        SwingUtilities2.drawString(rootPane, g, theTitle, xOffset,
                                   yOffset );
        xOffset += leftToRight ? titleLength + 5  : -5;
    }

    int bumpXOffset;
    int bumpLength;
    if( leftToRight ) {
        bumpLength = width - buttonsWidth - xOffset - 5;
        bumpXOffset = xOffset;
    } else {
        bumpLength = xOffset - buttonsWidth - 5;
        bumpXOffset = buttonsWidth + 5;
    }
    int bumpYOffset = 3;
    int bumpHeight = getHeight() - (2 * bumpYOffset);
    bumps.setBumpArea( bumpLength, bumpHeight );
    bumps.paintIcon(this, g, bumpXOffset, bumpYOffset);
}
 
Example 19
Source File: MotifBorders.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paints the border for the specified component with the
 * specified position and size.
 * @param c the component for which this border is being painted
 * @param g the paint graphics
 * @param x the x position of the painted border
 * @param y the y position of the painted border
 * @param width the width of the painted border
 * @param height the height of the painted border
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    if (!(c instanceof JPopupMenu)) {
        return;
    }

    Font origFont = g.getFont();
    Color origColor = g.getColor();
    JPopupMenu popup = (JPopupMenu)c;

    String title = popup.getLabel();
    if (title == null) {
        return;
    }

    g.setFont(font);

    FontMetrics fm = SwingUtilities2.getFontMetrics(popup, g, font);
    int         fontHeight = fm.getHeight();
    int         descent = fm.getDescent();
    int         ascent = fm.getAscent();
    Point       textLoc = new Point();
    int         stringWidth = SwingUtilities2.stringWidth(popup, fm,
                                                          title);

    textLoc.y = y + ascent + TEXT_SPACING;
    textLoc.x = x + ((width - stringWidth) / 2);

    g.setColor(background);
    g.fillRect(textLoc.x - TEXT_SPACING, textLoc.y - (fontHeight-descent),
               stringWidth + (2 * TEXT_SPACING), fontHeight - descent);
    g.setColor(foreground);
    SwingUtilities2.drawString(popup, g, title, textLoc.x, textLoc.y);

    MotifGraphicsUtils.drawGroove(g, x, textLoc.y + TEXT_SPACING,
                                  width, GROOVE_HEIGHT,
                                  shadowColor, highlightColor);

    g.setFont(origFont);
    g.setColor(origColor);
}
 
Example 20
Source File: WindowsInternalFrameTitlePane.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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);
    }
}