@Override public Dimension minimumLayoutSize(Container c) { // Compute width. int width = 30; if (frame.isClosable()) { width += 21; } if (frame.isMaximizable()) { width += 16 + (frame.isClosable() ? 10 : 4); } if (frame.isIconifiable()) { width += 16 + (frame.isMaximizable() ? 2 : (frame.isClosable() ? 10 : 4)); } FontMetrics fm = frame.getFontMetrics(getFont()); String frameTitle = frame.getTitle(); int title_w = frameTitle != null ? fm.stringWidth(frameTitle) : 0; int title_length = frameTitle != null ? frameTitle.length() : 0; if (title_length > 2) { int subtitle_w = fm.stringWidth(frame.getTitle().substring(0, 2) + "..."); width += (title_w < subtitle_w) ? title_w : subtitle_w; } else { width += title_w; } // Compute height. int height; // if (isPalette) { // height = paletteTitleHeight; // } else { int fontHeight = fm.getHeight(); fontHeight += 7; Icon icon = frame.getFrameIcon(); int iconHeight = 0; if (icon != null) { // SystemMenuBar forces the icon to be 16x16 or less. iconHeight = Math.min(icon.getIconHeight(), 16); } iconHeight += 5; height = Math.max(fontHeight, iconHeight); // } return new Dimension(width, height); }
/* * (non-Javadoc) * * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) */ @Override public void paintComponent(Graphics g) { // if (this.isPalette) { // this.paintPalette(g); // return; // } DecorationAreaType decorationType = getThisDecorationType(); Graphics2D graphics = (Graphics2D) g.create(); // Desktop icon is translucent. final float coef = (this.getParent() instanceof JDesktopIcon) ? 0.6f : 1.0f; graphics.setComposite(LafWidgetUtilities.getAlphaComposite(this.frame, coef, g)); boolean leftToRight = this.frame.getComponentOrientation().isLeftToRight(); int width = this.getWidth(); int height = this.getHeight() + 2; SubstanceColorScheme scheme = SubstanceCoreUtilities.getSkin(this.frame).getEnabledColorScheme(decorationType); JInternalFrame hostFrame = (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class, this); JComponent hostForColorization = hostFrame; if (hostFrame == null) { // try desktop icon JDesktopIcon desktopIcon = (JDesktopIcon) SwingUtilities.getAncestorOfClass(JDesktopIcon.class, this); if (desktopIcon != null) hostFrame = desktopIcon.getInternalFrame(); hostForColorization = desktopIcon; } // if ((hostFrame != null) && SubstanceCoreUtilities.hasColorization( // this)) { Color backgr = hostFrame.getBackground(); if (!(backgr instanceof UIResource)) { double colorization = SubstanceCoreUtilities.getColorizationFactor(hostForColorization); scheme = ShiftColorScheme.getShiftedScheme(scheme, backgr, colorization, null, 0.0); } // } String theTitle = this.frame.getTitle(); // offset of border int xOffset; int leftEnd; int rightEnd; if (leftToRight) { xOffset = 5; Icon icon = this.frame.getFrameIcon(); if (icon != null) { xOffset += icon.getIconWidth() + 5; } leftEnd = (this.menuBar == null) ? 0 : (this.menuBar.getWidth() + 5); xOffset += leftEnd; if (icon != null) leftEnd += (icon.getIconWidth() + 5); rightEnd = width - 5; // find the leftmost button for the right end AbstractButton leftmostButton = null; if (this.frame.isIconifiable()) { leftmostButton = this.iconButton; } else { if (this.frame.isMaximizable()) { leftmostButton = this.maxButton; } else { if (this.frame.isClosable()) { leftmostButton = this.closeButton; } } } if (leftmostButton != null) { Rectangle rect = leftmostButton.getBounds(); rightEnd = rect.getBounds().x - 5; } if (theTitle != null) { FontMetrics fm = this.frame.getFontMetrics(graphics.getFont()); int titleWidth = rightEnd - leftEnd; String clippedTitle = SubstanceCoreUtilities.clipString(fm, titleWidth, theTitle); // show tooltip with full title only if necessary if (theTitle.equals(clippedTitle)) this.setToolTipText(null); else this.setToolTipText(theTitle); theTitle = clippedTitle; } } else { xOffset = width - 5; Icon icon = this.frame.getFrameIcon(); if (icon != null) { xOffset -= (icon.getIconWidth() + 5); } rightEnd = (this.menuBar == null) ? xOffset : xOffset - this.menuBar.getWidth() - 5; // find the rightmost button for the left end AbstractButton rightmostButton = null; if (this.frame.isIconifiable()) { rightmostButton = this.iconButton; } else { if (this.frame.isMaximizable()) { rightmostButton = this.maxButton; } else { if (this.frame.isClosable()) { rightmostButton = this.closeButton; } } } leftEnd = 5; if (rightmostButton != null) { Rectangle rect = rightmostButton.getBounds(); leftEnd = rect.getBounds().x + 5; } if (theTitle != null) { FontMetrics fm = this.frame.getFontMetrics(graphics.getFont()); int titleWidth = rightEnd - leftEnd; String clippedTitle = SubstanceCoreUtilities.clipString(fm, titleWidth, theTitle); // show tooltip with full title only if necessary if (theTitle.equals(clippedTitle)) { this.setToolTipText(null); } else { this.setToolTipText(theTitle); } theTitle = clippedTitle; xOffset = rightEnd - fm.stringWidth(theTitle); } } BackgroundPaintingUtils.update( graphics, SubstanceInternalFrameTitlePane.this, false, decorationType); // DecorationPainterUtils.paintDecorationBackground(graphics, // SubstanceInternalFrameTitlePane.this, false); // draw the title (if needed) if (theTitle != null) { JRootPane rootPane = this.getRootPane(); FontMetrics fm = rootPane.getFontMetrics(graphics.getFont()); int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent(); SubstanceTextUtilities.paintTextWithDropShadow( this, graphics, SubstanceColorUtilities.getForegroundColor(scheme), theTitle, width, height, xOffset, yOffset); } Icon icon = this.frame.getFrameIcon(); if (icon != null) { if (leftToRight) { int iconY = ((height / 2) - (icon.getIconHeight() / 2)); icon.paintIcon(this.frame, graphics, 5, iconY); } else { int iconY = ((height / 2) - (icon.getIconHeight() / 2)); icon.paintIcon(this.frame, graphics, width - 5 - icon.getIconWidth(), iconY); } } graphics.dispose(); }