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

The following examples show how to use sun.swing.SwingUtilities2#clipStringIfNecessary() . 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: Metacity.java    From jdk1.8-source-analysis with Apache License 2.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 2
Source File: Metacity.java    From openjdk-8 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 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: 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 5
Source File: Metacity.java    From Bytecoder with Apache License 2.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 6
Source File: ComponentValidator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String trimMessage(String message, JComponent c) {
  String[] words = message.split("\\s+");
  StringBuilder result = new StringBuilder();

  for (String word : words) {
    word = SwingUtilities2.clipStringIfNecessary(c, c.getFontMetrics(c.getFont()), word, MAX_WIDTH.get());
    result.append(word).append(" ");
  }

  return result.toString();
}
 
Example 7
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 8
Source File: BasicInternalFrameTitlePane.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
  return SwingUtilities2.clipStringIfNecessary(
                     frame, fm, text, availTextWidth);
}
 
Example 9
Source File: BasicTabbedPaneUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected void paintTab(Graphics g, int tabPlacement,
                        Rectangle[] rects, int tabIndex,
                        Rectangle iconRect, Rectangle textRect) {
    Rectangle tabRect = rects[tabIndex];
    int selectedIndex = tabPane.getSelectedIndex();
    boolean isSelected = selectedIndex == tabIndex;

    if (tabsOpaque || tabPane.isOpaque()) {
        paintTabBackground(g, tabPlacement, tabIndex, tabRect.x, tabRect.y,
                tabRect.width, tabRect.height, isSelected);
    }

    paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y,
                   tabRect.width, tabRect.height, isSelected);

    String title = tabPane.getTitleAt(tabIndex);
    Font font = tabPane.getFont();
    FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
    Icon icon = getIconForTab(tabIndex);

    layoutLabel(tabPlacement, metrics, tabIndex, title, icon,
                tabRect, iconRect, textRect, isSelected);

    if (tabPane.getTabComponentAt(tabIndex) == null) {
        String clippedTitle = title;

        if (scrollableTabLayoutEnabled() && tabScroller.croppedEdge.isParamsSet() &&
                tabScroller.croppedEdge.getTabIndex() == tabIndex && isHorizontalTabPlacement()) {
            int availTextWidth = tabScroller.croppedEdge.getCropline() -
                    (textRect.x - tabRect.x) - tabScroller.croppedEdge.getCroppedSideWidth();
            clippedTitle = SwingUtilities2.clipStringIfNecessary(null, metrics, title, availTextWidth);
        } else if (!scrollableTabLayoutEnabled() && isHorizontalTabPlacement()) {
            clippedTitle = SwingUtilities2.clipStringIfNecessary(null, metrics, title, textRect.width);
        }

        paintText(g, tabPlacement, font, metrics,
                tabIndex, clippedTitle, textRect, isSelected);

        paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
    }
    paintFocusIndicator(g, tabPlacement, rects, tabIndex,
              iconRect, textRect, isSelected);
}
 
Example 10
Source File: MetalTitlePane.java    From openjdk-jdk8u-backup 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 11
Source File: BasicInternalFrameTitlePane.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
  return SwingUtilities2.clipStringIfNecessary(
                     frame, fm, text, availTextWidth);
}
 
Example 12
Source File: MetalTitlePane.java    From openjdk-jdk8u 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 13
Source File: BasicInternalFrameTitlePane.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
  return SwingUtilities2.clipStringIfNecessary(
                     frame, fm, text, availTextWidth);
}
 
Example 14
Source File: MetalTitlePane.java    From jdk8u-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 15
Source File: BasicInternalFrameTitlePane.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
  return SwingUtilities2.clipStringIfNecessary(
                     frame, fm, text, availTextWidth);
}
 
Example 16
Source File: BasicInternalFrameTitlePane.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
  return SwingUtilities2.clipStringIfNecessary(
                     frame, fm, text, availTextWidth);
}
 
Example 17
Source File: MetalTitlePane.java    From Java8CN with Apache License 2.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 18
Source File: DarculaTitlePane.java    From Darcula with Apache License 2.0 4 votes vote down vote up
public 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 19
Source File: SeaGlassTitlePane.java    From seaglass with Apache License 2.0 2 votes vote down vote up
/**
 * Get the title text, clipped if necessary.
 *
 * @param  text           the title text.
 * @param  fm             the font metrics to compute size with.
 * @param  availTextWidth the available space to display the title in.
 *
 * @return the text, clipped to fit the available space.
 */
private String getTitle(String text, FontMetrics fm, int availTextWidth) {
    return SwingUtilities2.clipStringIfNecessary(rootPane, fm, text, availTextWidth);
}
 
Example 20
Source File: BasicInternalFrameTitlePane.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the title.
 *
 * @param text a text
 * @param fm an instance of {@code FontMetrics}
 * @param availTextWidth an available text width
 * @return the title.
 */
protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
    return SwingUtilities2.clipStringIfNecessary(
                       frame, fm, text, availTextWidth);
}