1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51:
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60:
61:
62:
68: public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane
69: {
70:
71:
76: class MetalInternalFrameTitlePanePropertyChangeHandler
77: extends PropertyChangeHandler
78: {
79:
82: public MetalInternalFrameTitlePanePropertyChangeHandler()
83: {
84: super();
85: }
86:
87:
93: public void propertyChange(PropertyChangeEvent e)
94: {
95: String propName = e.getPropertyName();
96: if (propName.equals("JInternalFrame.isPalette"))
97: {
98: if (e.getNewValue().equals(Boolean.TRUE))
99: setPalette(true);
100: else
101: setPalette(false);
102: }
103: else
104: super.propertyChange(e);
105: }
106: }
107:
108:
113: private class MetalTitlePaneLayout implements LayoutManager
114: {
115:
118: public MetalTitlePaneLayout()
119: {
120:
121: }
122:
123:
129: public void addLayoutComponent(String name, Component c)
130: {
131:
132: }
133:
134:
139: public void layoutContainer(Container c)
140: {
141:
142: Dimension size = c.getSize();
143: Insets insets = c.getInsets();
144: int width = size.width - insets.left - insets.right;
145: int height = size.height - insets.top - insets.bottom;
146:
147:
148: int loc = width - insets.right - 1;
149: int top = insets.top + 2;
150: int buttonHeight = height - 4;
151: if (closeButton.isVisible())
152: {
153: int buttonWidth = closeIcon.getIconWidth();
154: loc -= buttonWidth + 2;
155: closeButton.setBounds(loc, top, buttonWidth, buttonHeight);
156: loc -= 6;
157: }
158:
159: if (maxButton.isVisible())
160: {
161: int buttonWidth = maxIcon.getIconWidth();
162: loc -= buttonWidth + 4;
163: maxButton.setBounds(loc, top, buttonWidth, buttonHeight);
164: }
165:
166: if (iconButton.isVisible())
167: {
168: int buttonWidth = minIcon.getIconWidth();
169: loc -= buttonWidth + 4;
170: iconButton.setBounds(loc, top, buttonWidth, buttonHeight);
171: loc -= 2;
172: }
173:
174: Dimension titlePreferredSize = title.getPreferredSize();
175: title.setBounds(insets.left + 5, insets.top,
176: Math.min(titlePreferredSize.width, loc - insets.left - 10),
177: height);
178:
179: }
180:
181:
189: public Dimension minimumLayoutSize(Container c)
190: {
191: return preferredLayoutSize(c);
192: }
193:
194:
202: public Dimension preferredLayoutSize(Container c)
203: {
204: if (isPalette)
205: return new Dimension(paletteTitleHeight, paletteTitleHeight);
206: else
207: return new Dimension(22, 22);
208: }
209:
210:
215: public void removeLayoutComponent(Component c)
216: {
217:
218: }
219: }
220:
221:
222: protected boolean isPalette;
223:
224:
228: protected Icon paletteCloseIcon;
229:
230:
235: protected int paletteTitleHeight;
236:
237:
238: JLabel title;
239:
240:
245: public MetalInternalFrameTitlePane(JInternalFrame f)
246: {
247: super(f);
248: isPalette = false;
249: }
250:
251:
254: protected void installDefaults()
255: {
256: super.installDefaults();
257: selectedTextColor = MetalLookAndFeel.getControlTextColor();
258: selectedTitleColor = MetalLookAndFeel.getWindowTitleBackground();
259: notSelectedTextColor = MetalLookAndFeel.getInactiveControlTextColor();
260: notSelectedTitleColor = MetalLookAndFeel.getWindowTitleInactiveBackground();
261:
262: paletteTitleHeight = UIManager.getInt("InternalFrame.paletteTitleHeight");
263: paletteCloseIcon = UIManager.getIcon("InternalFrame.paletteCloseIcon");
264: minIcon = MetalIconFactory.getInternalFrameAltMaximizeIcon(16);
265:
266: title = new JLabel(frame.getTitle(),
267: MetalIconFactory.getInternalFrameDefaultMenuIcon(),
268: SwingConstants.LEFT);
269: }
270:
271:
274: protected void uninstallDefaults()
275: {
276: super.uninstallDefaults();
277: selectedTextColor = null;
278: selectedTitleColor = null;
279: notSelectedTextColor = null;
280: notSelectedTitleColor = null;
281: paletteCloseIcon = null;
282: minIcon = null;
283: title = null;
284: }
285:
286:
291: protected void createButtons()
292: {
293: super.createButtons();
294: closeButton.setBorderPainted(false);
295: closeButton.setContentAreaFilled(false);
296: iconButton.setBorderPainted(false);
297: iconButton.setContentAreaFilled(false);
298: maxButton.setBorderPainted(false);
299: maxButton.setContentAreaFilled(false);
300: }
301:
302:
305: protected void addSystemMenuItems(JMenu systemMenu)
306: {
307:
308: }
309:
310:
313: protected void showSystemMenu()
314: {
315:
316: }
317:
318:
321: protected void addSubComponents()
322: {
323:
324:
325: add(title);
326: add(closeButton);
327: add(iconButton);
328: add(maxButton);
329: }
330:
331:
336: protected LayoutManager createLayout()
337: {
338: return new MetalTitlePaneLayout();
339: }
340:
341:
348: public void paintPalette(Graphics g)
349: {
350: Color savedColor = g.getColor();
351: Rectangle b = SwingUtilities.getLocalBounds(this);
352:
353: if (UIManager.get("InternalFrame.activeTitleGradient") != null
354: && frame.isSelected())
355: {
356: MetalUtils.paintGradient(g, b.x, b.y, b.width, b.height,
357: SwingConstants.VERTICAL,
358: "InternalFrame.activeTitleGradient");
359: }
360: MetalUtils.fillMetalPattern(this, g, b.x + 4, b.y + 2, b.width
361: - paletteCloseIcon.getIconWidth() - 13, b.height - 5,
362: MetalLookAndFeel.getPrimaryControlHighlight(),
363: MetalLookAndFeel.getBlack());
364:
365:
366: Dimension d = getSize();
367: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
368: g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
369:
370: g.setColor(savedColor);
371: }
372:
373:
378: public void paintComponent(Graphics g)
379: {
380: Color savedColor = g.getColor();
381: if (isPalette)
382: paintPalette(g);
383: else
384: {
385: paintTitleBackground(g);
386: paintChildren(g);
387: Dimension d = getSize();
388: if (frame.isSelected())
389: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
390: else
391: g.setColor(MetalLookAndFeel.getControlDarkShadow());
392:
393:
394: g.drawLine(0, 0, 0, 0);
395: g.drawLine(d.width - 1, 0, d.width - 1, 0);
396:
397: g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
398:
399:
400: if (UIManager.get("InternalFrame.activeTitleGradient") != null
401: && frame.isSelected())
402: {
403: MetalUtils.paintGradient(g, 0, 0, getWidth(), getHeight(),
404: SwingConstants.VERTICAL,
405: "InternalFrame.activeTitleGradient");
406: }
407:
408: Rectangle b = title.getBounds();
409: int startX = b.x + b.width + 5;
410: int endX = startX;
411: if (iconButton.isVisible())
412: endX = Math.max(iconButton.getX(), endX);
413: else if (maxButton.isVisible())
414: endX = Math.max(maxButton.getX(), endX);
415: else if (closeButton.isVisible())
416: endX = Math.max(closeButton.getX(), endX);
417: endX -= 7;
418: if (endX > startX)
419: MetalUtils.fillMetalPattern(this, g, startX, 3, endX - startX, getHeight() - 6, Color.white, Color.gray);
420: }
421: g.setColor(savedColor);
422: }
423:
424:
430: public void setPalette(boolean b)
431: {
432: isPalette = b;
433: title.setVisible(!isPalette);
434: iconButton.setVisible(!isPalette && frame.isIconifiable());
435: maxButton.setVisible(!isPalette && frame.isMaximizable());
436: if (isPalette)
437: closeButton.setIcon(paletteCloseIcon);
438: else
439: closeButton.setIcon(closeIcon);
440: }
441:
442:
447: protected PropertyChangeListener createPropertyChangeListener()
448: {
449: return new MetalInternalFrameTitlePanePropertyChangeHandler();
450: }
451: }