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 (e.getPropertyName().equals(JInternalFrame.FRAME_ICON_PROPERTY))
97: {
98: title.setIcon(frame.getFrameIcon());
99: }
100: else if (propName.equals("JInternalFrame.isPalette"))
101: {
102: if (e.getNewValue().equals(Boolean.TRUE))
103: setPalette(true);
104: else
105: setPalette(false);
106: }
107: else
108: super.propertyChange(e);
109: }
110: }
111:
112:
117: private class MetalTitlePaneLayout implements LayoutManager
118: {
119:
122: public MetalTitlePaneLayout()
123: {
124:
125: }
126:
127:
133: public void addLayoutComponent(String name, Component c)
134: {
135:
136: }
137:
138:
143: public void layoutContainer(Container c)
144: {
145:
146: Dimension size = c.getSize();
147: Insets insets = c.getInsets();
148: int width = size.width - insets.left - insets.right;
149: int height = size.height - insets.top - insets.bottom;
150:
151:
152: int loc = width - insets.right - 1;
153: int top = insets.top + 2;
154: int buttonHeight = height - 4;
155: if (closeButton.isVisible())
156: {
157: int buttonWidth = closeIcon.getIconWidth();
158: loc -= buttonWidth + 2;
159: closeButton.setBounds(loc, top, buttonWidth, buttonHeight);
160: loc -= 6;
161: }
162:
163: if (maxButton.isVisible())
164: {
165: int buttonWidth = maxIcon.getIconWidth();
166: loc -= buttonWidth + 4;
167: maxButton.setBounds(loc, top, buttonWidth, buttonHeight);
168: }
169:
170: if (iconButton.isVisible())
171: {
172: int buttonWidth = minIcon.getIconWidth();
173: loc -= buttonWidth + 4;
174: iconButton.setBounds(loc, top, buttonWidth, buttonHeight);
175: loc -= 2;
176: }
177:
178: Dimension titlePreferredSize = title.getPreferredSize();
179: title.setBounds(insets.left + 5, insets.top,
180: Math.min(titlePreferredSize.width, loc - insets.left - 10),
181: height);
182:
183: }
184:
185:
193: public Dimension minimumLayoutSize(Container c)
194: {
195: return preferredLayoutSize(c);
196: }
197:
198:
206: public Dimension preferredLayoutSize(Container c)
207: {
208: if (isPalette)
209: return new Dimension(paletteTitleHeight, paletteTitleHeight);
210: else
211: return new Dimension(22, 22);
212: }
213:
214:
219: public void removeLayoutComponent(Component c)
220: {
221:
222: }
223: }
224:
225:
226: protected boolean isPalette;
227:
228:
232: protected Icon paletteCloseIcon;
233:
234:
239: protected int paletteTitleHeight;
240:
241:
242: JLabel title;
243:
244:
249: public MetalInternalFrameTitlePane(JInternalFrame f)
250: {
251: super(f);
252: isPalette = false;
253: }
254:
255:
258: protected void installDefaults()
259: {
260: super.installDefaults();
261: selectedTextColor = MetalLookAndFeel.getControlTextColor();
262: selectedTitleColor = MetalLookAndFeel.getWindowTitleBackground();
263: notSelectedTextColor = MetalLookAndFeel.getInactiveControlTextColor();
264: notSelectedTitleColor = MetalLookAndFeel.getWindowTitleInactiveBackground();
265:
266: paletteTitleHeight = UIManager.getInt("InternalFrame.paletteTitleHeight");
267: paletteCloseIcon = UIManager.getIcon("InternalFrame.paletteCloseIcon");
268: minIcon = MetalIconFactory.getInternalFrameAltMaximizeIcon(16);
269:
270: title = new JLabel(frame.getTitle(),
271: MetalIconFactory.getInternalFrameDefaultMenuIcon(),
272: SwingConstants.LEFT);
273: }
274:
275:
278: protected void uninstallDefaults()
279: {
280: super.uninstallDefaults();
281: selectedTextColor = null;
282: selectedTitleColor = null;
283: notSelectedTextColor = null;
284: notSelectedTitleColor = null;
285: paletteCloseIcon = null;
286: minIcon = null;
287: title = null;
288: }
289:
290:
295: protected void createButtons()
296: {
297: super.createButtons();
298: closeButton.setBorderPainted(false);
299: closeButton.setContentAreaFilled(false);
300: iconButton.setBorderPainted(false);
301: iconButton.setContentAreaFilled(false);
302: maxButton.setBorderPainted(false);
303: maxButton.setContentAreaFilled(false);
304: }
305:
306:
309: protected void addSystemMenuItems(JMenu systemMenu)
310: {
311:
312: }
313:
314:
317: protected void showSystemMenu()
318: {
319:
320: }
321:
322:
325: protected void addSubComponents()
326: {
327:
328:
329: add(title);
330: add(closeButton);
331: add(iconButton);
332: add(maxButton);
333: }
334:
335:
341: protected LayoutManager createLayout()
342: {
343: return new MetalTitlePaneLayout();
344: }
345:
346:
353: public void paintPalette(Graphics g)
354: {
355: Color savedColor = g.getColor();
356: Rectangle b = SwingUtilities.getLocalBounds(this);
357:
358: if (UIManager.get("InternalFrame.activeTitleGradient") != null
359: && frame.isSelected())
360: {
361: MetalUtils.paintGradient(g, b.x, b.y, b.width, b.height,
362: SwingConstants.VERTICAL,
363: "InternalFrame.activeTitleGradient");
364: }
365: MetalUtils.fillMetalPattern(this, g, b.x + 4, b.y + 2, b.width
366: - paletteCloseIcon.getIconWidth() - 13, b.height - 5,
367: MetalLookAndFeel.getPrimaryControlHighlight(),
368: MetalLookAndFeel.getBlack());
369:
370:
371: Dimension d = getSize();
372: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
373: g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
374:
375: g.setColor(savedColor);
376: }
377:
378:
383: public void paintComponent(Graphics g)
384: {
385: Color savedColor = g.getColor();
386: if (isPalette)
387: paintPalette(g);
388: else
389: {
390: paintTitleBackground(g);
391: paintChildren(g);
392: Dimension d = getSize();
393: if (frame.isSelected())
394: g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
395: else
396: g.setColor(MetalLookAndFeel.getControlDarkShadow());
397:
398:
399: g.drawLine(0, 0, 0, 0);
400: g.drawLine(d.width - 1, 0, d.width - 1, 0);
401:
402: g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
403:
404:
405: if (UIManager.get("InternalFrame.activeTitleGradient") != null
406: && frame.isSelected())
407: {
408: MetalUtils.paintGradient(g, 0, 0, getWidth(), getHeight(),
409: SwingConstants.VERTICAL,
410: "InternalFrame.activeTitleGradient");
411: }
412:
413: Rectangle b = title.getBounds();
414: int startX = b.x + b.width + 5;
415: int endX = startX;
416: if (iconButton.isVisible())
417: endX = Math.max(iconButton.getX(), endX);
418: else if (maxButton.isVisible())
419: endX = Math.max(maxButton.getX(), endX);
420: else if (closeButton.isVisible())
421: endX = Math.max(closeButton.getX(), endX);
422: endX -= 7;
423: if (endX > startX)
424: MetalUtils.fillMetalPattern(this, g, startX, 3, endX - startX,
425: getHeight() - 6, Color.white, Color.gray);
426: }
427: g.setColor(savedColor);
428: }
429:
430:
436: public void setPalette(boolean b)
437: {
438: isPalette = b;
439: title.setVisible(!isPalette);
440: iconButton.setVisible(!isPalette && frame.isIconifiable());
441: maxButton.setVisible(!isPalette && frame.isMaximizable());
442: if (isPalette)
443: closeButton.setIcon(paletteCloseIcon);
444: else
445: closeButton.setIcon(closeIcon);
446: }
447:
448:
453: protected PropertyChangeListener createPropertyChangeListener()
454: {
455: return new MetalInternalFrameTitlePanePropertyChangeHandler();
456: }
457: }