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: import ;
61:
62:
63:
69: public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane
70: {
71:
72:
77: class MetalInternalFrameTitlePanePropertyChangeHandler
78: extends PropertyChangeHandler
79: {
80:
83: public MetalInternalFrameTitlePanePropertyChangeHandler()
84: {
85: super();
86: }
87:
88:
94: public void propertyChange(PropertyChangeEvent e)
95: {
96: String propName = e.getPropertyName();
97: if (propName.equals("JInternalFrame.isPalette"))
98: {
99: if (e.getNewValue().equals(Boolean.TRUE))
100: setPalette(true);
101: else
102: setPalette(false);
103: }
104: else
105: super.propertyChange(e);
106: }
107: }
108:
109:
114: private class MetalTitlePaneLayout implements LayoutManager
115: {
116:
119: public MetalTitlePaneLayout()
120: {
121:
122: }
123:
124:
130: public void addLayoutComponent(String name, Component c)
131: {
132:
133: }
134:
135:
140: public void layoutContainer(Container c)
141: {
142:
143: Dimension size = c.getSize();
144: Insets insets = c.getInsets();
145: int width = size.width - insets.left - insets.right;
146: int height = size.height - insets.top - insets.bottom;
147:
148:
149: int loc = width - insets.right - 1;
150: int top = insets.top + 2;
151: int buttonHeight = height - 4;
152: if (closeButton.isVisible())
153: {
154: int buttonWidth = closeIcon.getIconWidth();
155: loc -= buttonWidth + 2;
156: closeButton.setBounds(loc, top, buttonWidth, buttonHeight);
157: loc -= 6;
158: }
159:
160: if (maxButton.isVisible())
161: {
162: int buttonWidth = maxIcon.getIconWidth();
163: loc -= buttonWidth + 4;
164: maxButton.setBounds(loc, top, buttonWidth, buttonHeight);
165: }
166:
167: if (iconButton.isVisible())
168: {
169: int buttonWidth = minIcon.getIconWidth();
170: loc -= buttonWidth + 4;
171: iconButton.setBounds(loc, top, buttonWidth, buttonHeight);
172: loc -= 2;
173: }
174:
175: Dimension titlePreferredSize = title.getPreferredSize();
176: title.setBounds(insets.left + 5, insets.top,
177: Math.min(titlePreferredSize.width, loc - insets.left - 10),
178: height);
179:
180: }
181:
182:
190: public Dimension minimumLayoutSize(Container c)
191: {
192: return preferredLayoutSize(c);
193: }
194:
195:
203: public Dimension preferredLayoutSize(Container c)
204: {
205: if (isPalette)
206: return new Dimension(paletteTitleHeight, paletteTitleHeight);
207: else
208: return new Dimension(22, 22);
209: }
210:
211:
216: public void removeLayoutComponent(Component c)
217: {
218:
219: }
220: }
221:
222:
223: protected boolean isPalette;
224:
225:
229: protected Icon paletteCloseIcon;
230:
231:
236: protected int paletteTitleHeight;
237:
238:
239: JLabel title;
240:
241:
246: public MetalInternalFrameTitlePane(JInternalFrame f)
247: {
248: super(f);
249: isPalette = false;
250: }
251:
252:
255: protected void installDefaults()
256: {
257: super.installDefaults();
258: selectedTextColor = MetalLookAndFeel.getControlTextColor();
259: selectedTitleColor = MetalLookAndFeel.getWindowTitleBackground();
260: notSelectedTextColor = MetalLookAndFeel.getInactiveControlTextColor();
261: notSelectedTitleColor = MetalLookAndFeel.getWindowTitleInactiveBackground();
262:
263: UIDefaults defaults = UIManager.getLookAndFeelDefaults();
264: paletteTitleHeight = defaults.getInt("InternalFrame.paletteTitleHeight");
265: paletteCloseIcon = defaults.getIcon("InternalFrame.paletteCloseIcon");
266: minIcon = MetalIconFactory.getInternalFrameAltMaximizeIcon(16);
267:
268: title = new JLabel(frame.getTitle(),
269: MetalIconFactory.getInternalFrameDefaultMenuIcon(),
270: SwingConstants.LEFT);
271: }
272:
273:
276: protected void uninstallDefaults()
277: {
278: super.uninstallDefaults();
279: selectedTextColor = null;
280: selectedTitleColor = null;
281: notSelectedTextColor = null;
282: notSelectedTitleColor = null;
283: paletteCloseIcon = null;
284: minIcon = null;
285: title = null;
286: }
287:
288:
293: protected void createButtons()
294: {
295: super.createButtons();
296: closeButton.setBorderPainted(false);
297: closeButton.setContentAreaFilled(false);
298: iconButton.setBorderPainted(false);
299: iconButton.setContentAreaFilled(false);
300: maxButton.setBorderPainted(false);
301: maxButton.setContentAreaFilled(false);
302: }
303:
304:
307: protected void addSystemMenuItems(JMenu systemMenu)
308: {
309:
310: }
311:
312:
315: protected void showSystemMenu()
316: {
317:
318: }
319:
320:
323: protected void addSubComponents()
324: {
325:
326:
327: add(title);
328: add(closeButton);
329: add(iconButton);
330: add(maxButton);
331: }
332:
333:
338: protected LayoutManager createLayout()
339: {
340: return new MetalTitlePaneLayout();
341: }
342:
343:
350: public void paintPalette(Graphics g)
351: {
352: Color savedColor = g.getColor();
353: Rectangle b = SwingUtilities.getLocalBounds(this);
354: g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
355: g.fillRect(b.x, b.y, b.width, b.height);
356: MetalUtils.fillMetalPattern(this, g, b.x + 4, b.y + 2, b.width
357: - paletteCloseIcon.getIconWidth() - 13, b.height - 5,
358: MetalLookAndFeel.getPrimaryControlHighlight(),
359: MetalLookAndFeel.getBlack());
360:
361:
362: Dimension d = getSize();
363: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
364: g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
365:
366: g.setColor(savedColor);
367: }
368:
369:
374: public void paintComponent(Graphics g)
375: {
376: Color savedColor = g.getColor();
377: if (isPalette)
378: paintPalette(g);
379: else
380: {
381: paintTitleBackground(g);
382: paintChildren(g);
383: Dimension d = getSize();
384: if (frame.isSelected())
385: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
386: else
387: g.setColor(MetalLookAndFeel.getControlDarkShadow());
388:
389:
390: g.drawLine(0, 0, 0, 0);
391: g.drawLine(d.width - 1, 0, d.width - 1, 0);
392:
393: g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
394:
395:
396: Rectangle b = title.getBounds();
397: int startX = b.x + b.width + 5;
398: int endX = startX;
399: if (iconButton.isVisible())
400: endX = Math.max(iconButton.getX(), endX);
401: else if (maxButton.isVisible())
402: endX = Math.max(maxButton.getX(), endX);
403: else if (closeButton.isVisible())
404: endX = Math.max(closeButton.getX(), endX);
405: endX -= 7;
406: if (endX > startX)
407: MetalUtils.fillMetalPattern(this, g, startX, 3, endX - startX, getHeight() - 6, Color.white, Color.gray);
408: }
409: g.setColor(savedColor);
410: }
411:
412:
418: public void setPalette(boolean b)
419: {
420: isPalette = b;
421: title.setVisible(!isPalette);
422: iconButton.setVisible(!isPalette && frame.isIconifiable());
423: maxButton.setVisible(!isPalette && frame.isMaximizable());
424: if (isPalette)
425: closeButton.setIcon(paletteCloseIcon);
426: else
427: closeButton.setIcon(closeIcon);
428: }
429:
430:
435: protected PropertyChangeListener createPropertyChangeListener()
436: {
437: return new MetalInternalFrameTitlePanePropertyChangeHandler();
438: }
439: }