public void paintPalette(Graphics g) { boolean leftToRight = MetalUtils.isLeftToRight(frame); int width = getWidth(); int height = getHeight(); if (paletteBumps == null) { paletteBumps = new MetalBumps( 0, 0, MetalLookAndFeel.getPrimaryControlHighlight(), MetalLookAndFeel.getPrimaryControlInfo(), MetalLookAndFeel.getPrimaryControlShadow()); } Color background = MetalLookAndFeel.getPrimaryControlShadow(); Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow(); g.setColor(background); g.fillRect(0, 0, width, height); g.setColor(darkShadow); g.drawLine(0, height - 1, width, height - 1); int xOffset = leftToRight ? 4 : buttonsWidth + 4; int bumpLength = width - buttonsWidth - 2 * 4; int bumpHeight = getHeight() - 4; paletteBumps.setBumpArea(bumpLength, bumpHeight); paletteBumps.paintIcon(this, g, xOffset, 2); }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.translate(x, y); if (((JToolBar) c).isFloatable()) { if (((JToolBar) c).getOrientation() == HORIZONTAL) { int shift = MetalLookAndFeel.usingOcean() ? -1 : 0; bumps.setBumpArea(10, h - 4); if (MetalUtils.isLeftToRight(c)) { bumps.paintIcon(c, g, 2, 2 + shift); } else { bumps.paintIcon(c, g, w - 12, 2 + shift); } } else // vertical { bumps.setBumpArea(w - 4, 10); bumps.paintIcon(c, g, 2, 2); } } if (((JToolBar) c).getOrientation() == HORIZONTAL && MetalLookAndFeel.usingOcean()) { g.setColor(MetalLookAndFeel.getControl()); g.drawLine(0, h - 2, w, h - 2); g.setColor(UIManager.getColor("ToolBar.borderColor")); g.drawLine(0, h - 1, w, h - 1); } g.translate(-x, -y); }
public void layoutContainer(Container c) { boolean leftToRight = MetalUtils.isLeftToRight(frame); int w = getWidth(); int x = leftToRight ? w : 0; int y = 2; int spacing; // assumes all buttons have the same dimensions // these dimensions include the borders int buttonHeight = closeButton.getIcon().getIconHeight(); int buttonWidth = closeButton.getIcon().getIconWidth(); if (frame.isClosable()) { if (isPalette) { spacing = 3; x += leftToRight ? -spacing - (buttonWidth + 2) : spacing; closeButton.setBounds(x, y, buttonWidth + 2, getHeight() - 4); if (!leftToRight) x += (buttonWidth + 2); } else { spacing = 4; x += leftToRight ? -spacing - buttonWidth : spacing; closeButton.setBounds(x, y, buttonWidth, buttonHeight); if (!leftToRight) x += buttonWidth; } } if (frame.isMaximizable() && !isPalette) { spacing = frame.isClosable() ? 10 : 4; x += leftToRight ? -spacing - buttonWidth : spacing; maxButton.setBounds(x, y, buttonWidth, buttonHeight); if (!leftToRight) x += buttonWidth; } if (frame.isIconifiable() && !isPalette) { spacing = frame.isMaximizable() ? 2 : (frame.isClosable() ? 10 : 4); x += leftToRight ? -spacing - buttonWidth : spacing; iconButton.setBounds(x, y, buttonWidth, buttonHeight); if (!leftToRight) x += buttonWidth; } buttonsWidth = leftToRight ? w - x : x; }
public void paintComponent(Graphics g) { if (isPalette) { paintPalette(g); return; } boolean leftToRight = MetalUtils.isLeftToRight(frame); boolean isSelected = frame.isSelected(); int width = getWidth(); int height = getHeight(); Color background = null; Color foreground = null; Color shadow = null; MetalBumps bumps; String gradientKey; if (isSelected) { if (!MetalLookAndFeel.usingOcean()) { closeButton.setContentAreaFilled(true); maxButton.setContentAreaFilled(true); iconButton.setContentAreaFilled(true); } if (selectedBackgroundKey != null) { background = UIManager.getColor(selectedBackgroundKey); } if (background == null) { background = MetalLookAndFeel.getWindowTitleBackground(); } if (selectedForegroundKey != null) { foreground = UIManager.getColor(selectedForegroundKey); } if (selectedShadowKey != null) { shadow = UIManager.getColor(selectedShadowKey); } if (shadow == null) { shadow = MetalLookAndFeel.getPrimaryControlDarkShadow(); } if (foreground == null) { foreground = MetalLookAndFeel.getWindowTitleForeground(); } activeBumps.setBumpColors( activeBumpsHighlight, activeBumpsShadow, UIManager.get("InternalFrame.activeTitleGradient") != null ? null : background); bumps = activeBumps; gradientKey = "InternalFrame.activeTitleGradient"; } else { if (!MetalLookAndFeel.usingOcean()) { closeButton.setContentAreaFilled(false); maxButton.setContentAreaFilled(false); iconButton.setContentAreaFilled(false); } background = MetalLookAndFeel.getWindowTitleInactiveBackground(); foreground = MetalLookAndFeel.getWindowTitleInactiveForeground(); shadow = MetalLookAndFeel.getControlDarkShadow(); bumps = inactiveBumps; gradientKey = "InternalFrame.inactiveTitleGradient"; } if (!MetalUtils.drawGradient(this, g, gradientKey, 0, 0, width, height, true)) { g.setColor(background); g.fillRect(0, 0, width, height); } g.setColor(shadow); g.drawLine(0, height - 1, width, height - 1); g.drawLine(0, 0, 0, 0); g.drawLine(width - 1, 0, width - 1, 0); int titleLength = 0; int xOffset = leftToRight ? 5 : width - 5; String frameTitle = frame.getTitle(); Icon icon = frame.getFrameIcon(); if (icon != null) { if (!leftToRight) xOffset -= icon.getIconWidth(); int iconY = ((height / 2) - (icon.getIconHeight() / 2)); icon.paintIcon(frame, g, xOffset, iconY); xOffset += leftToRight ? icon.getIconWidth() + 5 : -5; } if (frameTitle != null) { Font f = getFont(); g.setFont(f); FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g, f); int fHeight = fm.getHeight(); g.setColor(foreground); int yOffset = ((height - fm.getHeight()) / 2) + fm.getAscent(); Rectangle rect = new Rectangle(0, 0, 0, 0); if (frame.isIconifiable()) { rect = iconButton.getBounds(); } else if (frame.isMaximizable()) { rect = maxButton.getBounds(); } else if (frame.isClosable()) { rect = closeButton.getBounds(); } int titleW; if (leftToRight) { if (rect.x == 0) { rect.x = frame.getWidth() - frame.getInsets().right - 2; } titleW = rect.x - xOffset - 4; frameTitle = getTitle(frameTitle, fm, titleW); } else { titleW = xOffset - rect.x - rect.width - 4; frameTitle = getTitle(frameTitle, fm, titleW); xOffset -= SwingUtilities2.stringWidth(frame, fm, frameTitle); } titleLength = SwingUtilities2.stringWidth(frame, fm, frameTitle); SwingUtilities2.drawString(frame, g, frameTitle, 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); }