Example usage for javax.swing JMenuBar getSize

List of usage examples for javax.swing JMenuBar getSize

Introduction

In this page you can find the example usage for javax.swing JMenuBar getSize.

Prototype

public Dimension getSize() 

Source Link

Document

Returns the size of this component in the form of a Dimension object.

Usage

From source file:edu.ku.brc.ui.UIRegistry.java

/**
 * Writes a string message into the BufferedImage on GlassPane and sets the main component's visibility to false and
 * shows the GlassPane./*from  w  ww . j  a v a2s  . co  m*/
 * @param msg the message
 * @param pointSize the Font point size for the message to be writen in
 */
public static GhostGlassPane writeGlassPaneMsg(final String msg, final int pointSize) {
    GhostGlassPane glassPane = getGlassPane();
    if (glassPane != null) {
        glassPane.finishDnD();
    }

    glassPane.setMaskingEvents(true);

    Component mainComp = get(MAINPANE);
    if (mainComp != null && glassPane != null) {
        JFrame frame = (JFrame) get(FRAME);
        frameRect = frame.getBounds();

        int y = 0;
        JMenuBar menuBar = null;
        Dimension size = mainComp.getSize();
        if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
            menuBar = frame.getJMenuBar();
            size.height += menuBar.getSize().height;
            y += menuBar.getSize().height;
        }
        BufferedImage buffer = getGlassPaneBufferedImage(size.width, size.height);
        Graphics2D g2 = buffer.createGraphics();
        if (menuBar != null) {
            menuBar.paint(g2);
        }
        g2.translate(0, y);
        mainComp.paint(g2);
        g2.translate(0, -y);

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(new Color(255, 255, 255, 128));
        g2.fillRect(0, 0, size.width, size.height);

        g2.setFont(new Font((new JLabel()).getFont().getName(), Font.BOLD, pointSize));
        FontMetrics fm = g2.getFontMetrics();

        int tw = fm.stringWidth(msg);
        int th = fm.getHeight();
        int tx = (size.width - tw) / 2;
        int ty = (size.height - th) / 2;

        int expand = 20;
        int arc = expand * 2;
        g2.setColor(Color.WHITE);
        g2.fillRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc,
                arc);

        g2.setColor(Color.DARK_GRAY);
        g2.drawRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc,
                arc);

        g2.setColor(Color.BLACK);
        g2.drawString(msg, tx, ty);
        g2.dispose();

        glassPane.setImage(buffer);
        glassPane.setPoint(new Point(0, 0), GhostGlassPane.ImagePaintMode.ABSOLUTE);
        glassPane.setOffset(new Point(0, 0));

        glassPane.setVisible(true);
        mainComp.setVisible(false);

        //Using paintImmediately fixes problems with glass pane not showing, such as for workbench saves initialed
        //during workbench or app shutdown. Don't know if there is a better way to fix it.
        //glassPane.repaint();
        glassPane.paintImmediately(glassPane.getBounds());
        showingGlassPane = true;
    }

    return glassPane;
}