WindowsInternalFrameTitlePanepublic class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane
Fields Summary |
---|
private Color | selectedTitleGradientColor | private Color | notSelectedTitleGradientColor | private JPopupMenu | systemPopupMenu | private JLabel | systemLabel | private Font | titleFont | private int | titlePaneHeight | private int | buttonWidth | private int | buttonHeight | private boolean | hotTrackingOn |
Constructors Summary |
---|
public WindowsInternalFrameTitlePane(JInternalFrame f)
super(f);
|
Methods Summary |
---|
protected void | addSubComponents()
add(systemLabel);
add(iconButton);
add(maxButton);
add(closeButton);
| protected void | addSystemMenuItems(javax.swing.JPopupMenu menu)
JMenuItem mi = (JMenuItem)menu.add(restoreAction);
mi.setMnemonic('R");
mi = (JMenuItem)menu.add(moveAction);
mi.setMnemonic('M");
mi = (JMenuItem)menu.add(sizeAction);
mi.setMnemonic('S");
mi = (JMenuItem)menu.add(iconifyAction);
mi.setMnemonic('n");
mi = (JMenuItem)menu.add(maximizeAction);
mi.setMnemonic('x");
systemPopupMenu.add(new JSeparator());
mi = (JMenuItem)menu.add(closeAction);
mi.setMnemonic('C");
| protected void | assembleSystemMenu()
systemPopupMenu = new JPopupMenu();
addSystemMenuItems(systemPopupMenu);
enableActions();
systemLabel = new JLabel(frame.getFrameIcon()) {
protected void paintComponent(Graphics g) {
int x = 0;
int y = 0;
int w = getWidth();
int h = getHeight();
g = g.create(); // Create scratch graphics
if (isOpaque()) {
g.setColor(getBackground());
g.fillRect(0, 0, w, h);
}
Icon icon = getIcon();
int iconWidth = 0;
int iconHeight = 0;
if (icon != null &&
(iconWidth = icon.getIconWidth()) > 0 &&
(iconHeight = icon.getIconHeight()) > 0) {
// Set drawing scale to make icon scale to our desired size
double drawScale;
if (iconWidth > iconHeight) {
// Center icon vertically
y = (h - w*iconHeight/iconWidth) / 2;
drawScale = w / (double)iconWidth;
} else {
// Center icon horizontally
x = (w - h*iconWidth/iconHeight) / 2;
drawScale = h / (double)iconHeight;
}
((Graphics2D)g).translate(x, y);
((Graphics2D)g).scale(drawScale, drawScale);
icon.paintIcon(this, g, 0, 0);
}
g.dispose();
}
};
systemLabel.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && frame.isClosable() &&
!frame.isIcon()) {
systemPopupMenu.setVisible(false);
frame.doDefaultCloseAction();
}
else {
super.mouseClicked(e);
}
}
public void mousePressed(MouseEvent e) {
try {
frame.setSelected(true);
} catch(PropertyVetoException pve) {
}
showSystemPopupMenu(e.getComponent());
}
});
| protected void | createButtons()
super.createButtons();
if (XPStyle.getXP() != null) {
iconButton.setContentAreaFilled(false);
maxButton.setContentAreaFilled(false);
closeButton.setContentAreaFilled(false);
}
| protected java.awt.LayoutManager | createLayout()
return new WindowsTitlePaneLayout();
| protected java.beans.PropertyChangeListener | createPropertyChangeListener()
return new WindowsPropertyChangeHandler();
| public java.awt.Dimension | getMinimumSize()
Dimension d = new Dimension(super.getMinimumSize());
d.height = titlePaneHeight + 2;
XPStyle xp = XPStyle.getXP();
if (xp != null) {
// Note: Don't know how to calculate height on XP,
// the captionbarheight is 25 but native caption is 30 (maximized 26)
if (frame.isMaximum()) {
d.height -= 1;
} else {
d.height += 3;
}
}
return d;
| public java.awt.Dimension | getPreferredSize()
return getMinimumSize();
| protected void | installDefaults()
super.installDefaults();
titlePaneHeight = UIManager.getInt("InternalFrame.titlePaneHeight");
buttonWidth = UIManager.getInt("InternalFrame.titleButtonWidth") - 4;
buttonHeight = UIManager.getInt("InternalFrame.titleButtonHeight") - 4;
Object obj = UIManager.get("InternalFrame.titleButtonToolTipsOn");
hotTrackingOn = (obj instanceof Boolean) ? (Boolean)obj : true;
if (XPStyle.getXP() != null) {
// Fix for XP bug where sometimes these sizes aren't updated properly
// Assume for now that height is correct and derive width using the
// ratio from the uxtheme part
buttonWidth = buttonHeight;
Dimension d = XPStyle.getPartSize(Part.WP_CLOSEBUTTON, State.NORMAL);
if (d != null && d.width != 0 && d.height != 0) {
buttonWidth = (int) ((float) buttonWidth * d.width / d.height);
}
} else {
buttonWidth += 2;
selectedTitleGradientColor =
UIManager.getColor("InternalFrame.activeTitleGradient");
notSelectedTitleGradientColor =
UIManager.getColor("InternalFrame.inactiveTitleGradient");
Color activeBorderColor =
UIManager.getColor("InternalFrame.activeBorderColor");
setBorder(BorderFactory.createLineBorder(activeBorderColor, 1));
}
| public void | paintComponent(java.awt.Graphics g)
XPStyle xp = XPStyle.getXP();
paintTitleBackground(g);
String title = frame.getTitle();
if (title != null) {
boolean isSelected = frame.isSelected();
Font oldFont = g.getFont();
Font newFont = (titleFont != null) ? titleFont : getFont();
g.setFont(newFont);
// Center text vertically.
FontMetrics fm = SwingUtilities2.getFontMetrics(frame, g, newFont);
int baseline = (getHeight() + fm.getAscent() - fm.getLeading() -
fm.getDescent()) / 2;
int titleX;
Rectangle r = new Rectangle(0, 0, 0, 0);
if (frame.isIconifiable()) r = iconButton.getBounds();
else if (frame.isMaximizable()) r = maxButton.getBounds();
else if (frame.isClosable()) r = closeButton.getBounds();
int titleW;
if(WindowsGraphicsUtils.isLeftToRight(frame) ) {
if (r.x == 0) r.x = frame.getWidth()-frame.getInsets().right;
titleX = systemLabel.getX() + systemLabel.getWidth() + 2;
if (xp != null) {
titleX += 2;
}
titleW = r.x - titleX - 3;
title = getTitle(frame.getTitle(), fm, titleW);
} else {
titleX = systemLabel.getX() - 2
- SwingUtilities2.stringWidth(frame,fm,title);
}
if (xp != null) {
String shadowType = null;
if (isSelected) {
shadowType = xp.getString(this, Part.WP_CAPTION,
State.ACTIVE, Prop.TEXTSHADOWTYPE);
}
if ("single".equalsIgnoreCase(shadowType)) {
Point shadowOffset = xp.getPoint(this, Part.WP_WINDOW, State.ACTIVE,
Prop.TEXTSHADOWOFFSET);
Color shadowColor = xp.getColor(this, Part.WP_WINDOW, State.ACTIVE,
Prop.TEXTSHADOWCOLOR, null);
if (shadowOffset != null && shadowColor != null) {
g.setColor(shadowColor);
SwingUtilities2.drawString(frame, g, title,
titleX + shadowOffset.x,
baseline + shadowOffset.y);
}
}
}
g.setColor(isSelected ? selectedTextColor : notSelectedTextColor);
SwingUtilities2.drawString(frame, g, title, titleX, baseline);
g.setFont(oldFont);
}
| protected void | paintTitleBackground(java.awt.Graphics g)
XPStyle xp = XPStyle.getXP();
if (xp != null) {
Part part = frame.isIcon() ? Part.WP_MINCAPTION
: (frame.isMaximum() ? Part.WP_MAXCAPTION
: Part.WP_CAPTION);
State state = frame.isSelected() ? State.ACTIVE : State.INACTIVE;
Skin skin = xp.getSkin(this, part);
skin.paintSkin(g, 0, 0, getWidth(), getHeight(), state);
} else {
Boolean gradientsOn = (Boolean)LookAndFeel.getDesktopPropertyValue(
"win.frame.captionGradientsOn", Boolean.valueOf(false));
if (gradientsOn.booleanValue() && g instanceof Graphics2D) {
Graphics2D g2 = (Graphics2D)g;
Paint savePaint = g2.getPaint();
boolean isSelected = frame.isSelected();
int w = getWidth();
if (isSelected) {
GradientPaint titleGradient = new GradientPaint(0,0,
selectedTitleColor,
(int)(w*.75),0,
selectedTitleGradientColor);
g2.setPaint(titleGradient);
} else {
GradientPaint titleGradient = new GradientPaint(0,0,
notSelectedTitleColor,
(int)(w*.75),0,
notSelectedTitleGradientColor);
g2.setPaint(titleGradient);
}
g2.fillRect(0, 0, getWidth(), getHeight());
g2.setPaint(savePaint);
} else {
super.paintTitleBackground(g);
}
}
| protected void | setButtonIcons()
super.setButtonIcons();
if (!hotTrackingOn) {
iconButton.setToolTipText(null);
maxButton.setToolTipText(null);
closeButton.setToolTipText(null);
}
| protected void | showSystemMenu()
showSystemPopupMenu(systemLabel);
| private void | showSystemPopupMenu(java.awt.Component invoker)
Dimension dim = new Dimension();
Border border = frame.getBorder();
if (border != null) {
dim.width += border.getBorderInsets(frame).left +
border.getBorderInsets(frame).right;
dim.height += border.getBorderInsets(frame).bottom +
border.getBorderInsets(frame).top;
}
if (!frame.isIcon()) {
systemPopupMenu.show(invoker,
getX() - dim.width,
getY() + getHeight() - dim.height);
} else {
systemPopupMenu.show(invoker,
getX() - dim.width,
getY() - systemPopupMenu.getPreferredSize().height -
dim.height);
}
| protected void | uninstallListeners()
// Get around protected method in superclass
super.uninstallListeners();
|
|