< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java

Print this page




 463 
 464             // Center text vertically.
 465             FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
 466             int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
 467                     fm.getDescent()) / 2;
 468 
 469             int titleX;
 470             Rectangle r = new Rectangle(0, 0, 0, 0);
 471             if (frame.isIconifiable())  r = iconButton.getBounds();
 472             else if (frame.isMaximizable())  r = maxButton.getBounds();
 473             else if (frame.isClosable())  r = closeButton.getBounds();
 474             int titleW;
 475 
 476             String title = frame.getTitle();
 477             if( BasicGraphicsUtils.isLeftToRight(frame) ) {
 478               if (r.x == 0)  r.x = frame.getWidth()-frame.getInsets().right;
 479               titleX = menuBar.getX() + menuBar.getWidth() + 2;
 480               titleW = r.x - titleX - 3;
 481               title = getTitle(frame.getTitle(), fm, titleW);
 482             } else {
 483                 titleX = menuBar.getX() - 2
 484                          - SwingUtilities2.stringWidth(frame,fm,title);
 485             }
 486 
 487             SwingUtilities2.drawString(frame, g, title, titleX, baseline);

 488             g.setFont(f);
 489         }
 490     }
 491 
 492    /**
 493     * Invoked from paintComponent.
 494     * Paints the background of the titlepane.  All text and icons will
 495     * then be rendered on top of this background.
 496     * @param g the graphics to use to render the background
 497     * @since 1.4
 498     */
 499     protected void paintTitleBackground(Graphics g) {
 500         boolean isSelected = frame.isSelected();
 501 
 502         if(isSelected)
 503             g.setColor(selectedTitleColor);
 504         else
 505             g.setColor(notSelectedTitleColor);
 506         g.fillRect(0, 0, getWidth(), getHeight());
 507     }
 508 
 509     /**
 510      * Returns the title.
 511      *
 512      * @param text a text
 513      * @param fm an instance of {@code FontMetrics}
 514      * @param availTextWidth an available text width
 515      * @return the title.
 516      */
 517     protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
 518         return SwingUtilities2.clipStringIfNecessary(
 519                            frame, fm, text, availTextWidth);
 520     }
 521 
 522     /**
 523      * Post a WINDOW_CLOSING-like event to the frame, so that it can
 524      * be treated like a regular {@code Frame}.
 525      *
 526      * @param frame an instance of {@code JInternalFrame}
 527      */
 528     protected void postClosingEvent(JInternalFrame frame) {
 529         InternalFrameEvent e = new InternalFrameEvent(
 530             frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING);
 531         // Try posting event, unless there's a SecurityManager.
 532         try {
 533             Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
 534         } catch (SecurityException se) {
 535             frame.dispatchEvent(e);
 536         }
 537     }
 538 


 629         public Dimension preferredLayoutSize(Container c) {
 630             return minimumLayoutSize(c);
 631         }
 632 
 633         public Dimension minimumLayoutSize(Container c) {
 634             // Calculate width.
 635             int width = 22;
 636 
 637             if (frame.isClosable()) {
 638                 width += 19;
 639             }
 640             if (frame.isMaximizable()) {
 641                 width += 19;
 642             }
 643             if (frame.isIconifiable()) {
 644                 width += 19;
 645             }
 646 
 647             FontMetrics fm = frame.getFontMetrics(getFont());
 648             String frameTitle = frame.getTitle();
 649             int title_w = frameTitle != null ? SwingUtilities2.stringWidth(

 650                                frame, fm, frameTitle) : 0;
 651             int title_length = frameTitle != null ? frameTitle.length() : 0;
 652 
 653             // Leave room for three characters in the title.
 654             if (title_length > 3) {
 655                 int subtitle_w = SwingUtilities2.stringWidth(
 656                     frame, fm, frameTitle.substring(0, 3) + "...");

 657                 width += (title_w < subtitle_w) ? title_w : subtitle_w;
 658             } else {
 659                 width += title_w;
 660             }
 661 
 662             // Calculate height.
 663             Icon icon = frame.getFrameIcon();
 664             int fontHeight = fm.getHeight();
 665             fontHeight += 2;
 666             int iconHeight = 0;
 667             if (icon != null) {
 668                 // SystemMenuBar forces the icon to be 16x16 or less.
 669                 iconHeight = Math.min(icon.getIconHeight(), 16);
 670             }
 671             iconHeight += 2;
 672 
 673             int height = Math.max( fontHeight, iconHeight );
 674 
 675             Dimension dim = new Dimension(width, height);
 676 




 463 
 464             // Center text vertically.
 465             FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g);
 466             int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
 467                     fm.getDescent()) / 2;
 468 
 469             int titleX;
 470             Rectangle r = new Rectangle(0, 0, 0, 0);
 471             if (frame.isIconifiable())  r = iconButton.getBounds();
 472             else if (frame.isMaximizable())  r = maxButton.getBounds();
 473             else if (frame.isClosable())  r = closeButton.getBounds();
 474             int titleW;
 475 
 476             String title = frame.getTitle();
 477             if( BasicGraphicsUtils.isLeftToRight(frame) ) {
 478               if (r.x == 0)  r.x = frame.getWidth()-frame.getInsets().right;
 479               titleX = menuBar.getX() + menuBar.getWidth() + 2;
 480               titleW = r.x - titleX - 3;
 481               title = getTitle(frame.getTitle(), fm, titleW);
 482             } else {
 483                 titleX = menuBar.getX() - 2 - SwingUtilities2
 484                         .getTextUIDrawing(frame).getStringWidth(frame, fm, title);
 485             }
 486 
 487             SwingUtilities2.getTextUIDrawing(frame)
 488                     .drawString(frame, g, title, titleX, baseline);
 489             g.setFont(f);
 490         }
 491     }
 492 
 493    /**
 494     * Invoked from paintComponent.
 495     * Paints the background of the titlepane.  All text and icons will
 496     * then be rendered on top of this background.
 497     * @param g the graphics to use to render the background
 498     * @since 1.4
 499     */
 500     protected void paintTitleBackground(Graphics g) {
 501         boolean isSelected = frame.isSelected();
 502 
 503         if(isSelected)
 504             g.setColor(selectedTitleColor);
 505         else
 506             g.setColor(notSelectedTitleColor);
 507         g.fillRect(0, 0, getWidth(), getHeight());
 508     }
 509 
 510     /**
 511      * Returns the title.
 512      *
 513      * @param text a text
 514      * @param fm an instance of {@code FontMetrics}
 515      * @param availTextWidth an available text width
 516      * @return the title.
 517      */
 518     protected String getTitle(String text, FontMetrics fm, int availTextWidth) {
 519         return SwingUtilities2.getTextUIDrawing(frame).getClippedString(
 520                            frame, fm, text, availTextWidth);
 521     }
 522 
 523     /**
 524      * Post a WINDOW_CLOSING-like event to the frame, so that it can
 525      * be treated like a regular {@code Frame}.
 526      *
 527      * @param frame an instance of {@code JInternalFrame}
 528      */
 529     protected void postClosingEvent(JInternalFrame frame) {
 530         InternalFrameEvent e = new InternalFrameEvent(
 531             frame, InternalFrameEvent.INTERNAL_FRAME_CLOSING);
 532         // Try posting event, unless there's a SecurityManager.
 533         try {
 534             Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
 535         } catch (SecurityException se) {
 536             frame.dispatchEvent(e);
 537         }
 538     }
 539 


 630         public Dimension preferredLayoutSize(Container c) {
 631             return minimumLayoutSize(c);
 632         }
 633 
 634         public Dimension minimumLayoutSize(Container c) {
 635             // Calculate width.
 636             int width = 22;
 637 
 638             if (frame.isClosable()) {
 639                 width += 19;
 640             }
 641             if (frame.isMaximizable()) {
 642                 width += 19;
 643             }
 644             if (frame.isIconifiable()) {
 645                 width += 19;
 646             }
 647 
 648             FontMetrics fm = frame.getFontMetrics(getFont());
 649             String frameTitle = frame.getTitle();
 650             int title_w = frameTitle != null ? SwingUtilities2
 651                     .getTextUIDrawing(frame).getStringWidth(
 652                                frame, fm, frameTitle) : 0;
 653             int title_length = frameTitle != null ? frameTitle.length() : 0;
 654 
 655             // Leave room for three characters in the title.
 656             if (title_length > 3) {
 657                 int subtitle_w = SwingUtilities2.getTextUIDrawing(frame)
 658                         .getStringWidth(frame, fm,
 659                                 frameTitle.substring(0, 3) + "...");
 660                 width += (title_w < subtitle_w) ? title_w : subtitle_w;
 661             } else {
 662                 width += title_w;
 663             }
 664 
 665             // Calculate height.
 666             Icon icon = frame.getFrameIcon();
 667             int fontHeight = fm.getHeight();
 668             fontHeight += 2;
 669             int iconHeight = 0;
 670             if (icon != null) {
 671                 // SystemMenuBar forces the icon to be 16x16 or less.
 672                 iconHeight = Math.min(icon.getIconHeight(), 16);
 673             }
 674             iconHeight += 2;
 675 
 676             int height = Math.max( fontHeight, iconHeight );
 677 
 678             Dimension dim = new Dimension(width, height);
 679 


< prev index next >