/* * Copyright 2005 MH-Software-Entwicklung. All rights reserved. * Use is subject to license terms. */ package com.jtattoo.plaf.mcwin; import java.awt.*; import javax.swing.*; import com.jtattoo.plaf.*; /** * @author Michael Hagen */ public class McWinTitlePane extends BaseTitlePane { public McWinTitlePane(JRootPane root, BaseRootPaneUI ui) { super(root, ui); } public LayoutManager createLayout() { return new TitlePaneLayout(); } public void createButtons() { iconifyButton = new BaseTitleButton(iconifyAction, ICONIFY, iconifyIcon, 1.0f); maxButton = new BaseTitleButton(restoreAction, MAXIMIZE, maximizeIcon, 1.0f); closeButton = new BaseTitleButton(closeAction, CLOSE, closeIcon, 1.0f); } public void paintBorder(Graphics g) { if (isActive()) { g.setColor(AbstractLookAndFeel.getTheme().getWindowBorderColor()); } else { g.setColor(AbstractLookAndFeel.getTheme().getWindowInactiveBorderColor()); } g.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1); } public void paintText(Graphics g, int x, int y, String title) { if (isActive()) { g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getWindowTitleColorLight(), 40)); JTattooUtilities.drawString(rootPane, g, title, x, y + 1); g.setColor(AbstractLookAndFeel.getWindowTitleForegroundColor()); JTattooUtilities.drawString(rootPane, g, title, x, y); } else { g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getWindowInactiveTitleColorLight(), 40)); JTattooUtilities.drawString(rootPane, g, title, x, y + 1); g.setColor(AbstractLookAndFeel.getWindowInactiveTitleForegroundColor()); JTattooUtilities.drawString(rootPane, g, title, x, y); } } //------------------------------------------------------------------------------ // inner classes //------------------------------------------------------------------------------ protected class TitlePaneLayout implements LayoutManager { public void addLayoutComponent(String name, Component c) { } public void removeLayoutComponent(Component c) { } public Dimension preferredLayoutSize(Container c) { int height = computeHeight(); return new Dimension(height, height); } public Dimension minimumLayoutSize(Container c) { return preferredLayoutSize(c); } protected int computeHeight() { FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(getFont()); return fm.getHeight() + 6; } public void layoutContainer(Container c) { boolean leftToRight = isLeftToRight(); int w = getWidth(); int h = getHeight(); // assumes all buttons have the same dimensions these dimensions include the borders int spacing = 4; int buttonHeight = 26; if (h <= 22) { spacing = 2; buttonHeight = 18; } else if (h <= 25) { spacing = 3; buttonHeight = 22; } else { spacing = 4; buttonHeight = 26; } int buttonWidth = buttonHeight; int x = leftToRight ? spacing : w - buttonWidth - spacing; int y = Math.max(0, ((h - buttonHeight) / 2) - 1); int cpx = 0; int cpy = 0; int cpw = getWidth(); int cph = getHeight(); if (menuBar != null) { int mw = menuBar.getPreferredSize().width; int mh = menuBar.getPreferredSize().height; if (leftToRight) { cpx = 4 + mw; menuBar.setBounds(2, (h - mh) / 2, mw, mh); } else { menuBar.setBounds(getWidth() - mw, (h - mh) / 2, mw, mh); } cpw -= 4 + mw; } x = leftToRight ? w - spacing : 0; if (closeButton != null) { x += leftToRight ? -buttonWidth : spacing; closeButton.setBounds(x, y, buttonWidth, buttonHeight); if (!leftToRight) { x += buttonWidth; } } if ((maxButton != null) && (maxButton.getParent() != null)) { if (DecorationHelper.isFrameStateSupported(Toolkit.getDefaultToolkit(), BaseRootPaneUI.MAXIMIZED_BOTH)) { x += leftToRight ? -spacing - buttonWidth : spacing; maxButton.setBounds(x, y, buttonWidth, buttonHeight); if (!leftToRight) { x += buttonWidth; } } } if ((iconifyButton != null) && (iconifyButton.getParent() != null)) { x += leftToRight ? -spacing - buttonWidth : spacing; iconifyButton.setBounds(x, y, buttonWidth, buttonHeight); if (!leftToRight) { x += buttonWidth; } } buttonsWidth = leftToRight ? w - x : x; if (customTitlePanel != null) { if (!leftToRight) { cpx += buttonsWidth; } cpw -= buttonsWidth; Graphics g = getGraphics(); if (g != null) { FontMetrics fm = g.getFontMetrics(); int tw = SwingUtilities.computeStringWidth(fm, JTattooUtilities.getClippedText(getTitle(), fm, cpw)); if (leftToRight) { cpx += tw; } cpw -= tw; } customTitlePanel.setBounds(cpx, cpy, cpw, cph); } } } // TitlePaneLayout }