38 |
|
|
39 |
package javax.swing.plaf.metal; |
package javax.swing.plaf.metal; |
40 |
|
|
41 |
|
import java.beans.PropertyChangeEvent; |
42 |
|
import java.beans.PropertyChangeListener; |
43 |
|
|
44 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
45 |
import javax.swing.JInternalFrame; |
import javax.swing.JInternalFrame; |
|
import javax.swing.border.EmptyBorder; |
|
46 |
import javax.swing.plaf.ComponentUI; |
import javax.swing.plaf.ComponentUI; |
47 |
import javax.swing.plaf.basic.BasicInternalFrameUI; |
import javax.swing.plaf.basic.BasicInternalFrameUI; |
48 |
|
|
53 |
public class MetalInternalFrameUI |
public class MetalInternalFrameUI |
54 |
extends BasicInternalFrameUI |
extends BasicInternalFrameUI |
55 |
{ |
{ |
56 |
|
/** |
57 |
|
* The key for the client property that controls whether the internal frame |
58 |
|
* is displayed using the palette style. |
59 |
|
*/ |
60 |
|
protected static String IS_PALETTE = "JInternalFrame.isPalette"; |
61 |
|
|
62 |
/** |
/** |
63 |
* Constructs a new instance of <code>MetalInternalFrameUI</code>. |
* Constructs a new instance of <code>MetalInternalFrameUI</code>. |
72 |
/** |
/** |
73 |
* Returns an instance of <code>MetalInternalFrameUI</code>. |
* Returns an instance of <code>MetalInternalFrameUI</code>. |
74 |
* |
* |
75 |
* @param component the component for which we return an UI instance |
* @param component the internal frame. |
76 |
* |
* |
77 |
* @return an instance of MetalInternalFrameUI |
* @return an instance of <code>MetalInternalFrameUI</code>. |
78 |
*/ |
*/ |
79 |
public static ComponentUI createUI(JComponent component) |
public static ComponentUI createUI(JComponent component) |
80 |
{ |
{ |
82 |
} |
} |
83 |
|
|
84 |
/** |
/** |
85 |
|
* Sets the fields and properties for the component. |
86 |
|
* |
87 |
|
* @param c the component. |
88 |
|
*/ |
89 |
|
public void installUI(JComponent c) |
90 |
|
{ |
91 |
|
super.installUI(c); |
92 |
|
JInternalFrame f = (JInternalFrame) c; |
93 |
|
boolean isPalette = false; |
94 |
|
Boolean p = (Boolean) f.getClientProperty(IS_PALETTE); |
95 |
|
if (p != null) |
96 |
|
isPalette = p.booleanValue(); |
97 |
|
setPalette(isPalette); |
98 |
|
} |
99 |
|
|
100 |
|
/** |
101 |
* Creates and returns the component that will be used for the north pane |
* Creates and returns the component that will be used for the north pane |
102 |
* of the {@link JInternalFrame}. |
* of the {@link JInternalFrame}. |
103 |
* |
* |
108 |
protected JComponent createNorthPane(JInternalFrame w) |
protected JComponent createNorthPane(JInternalFrame w) |
109 |
{ |
{ |
110 |
titlePane = new MetalInternalFrameTitlePane(w); |
titlePane = new MetalInternalFrameTitlePane(w); |
|
titlePane.setBorder(new EmptyBorder(2, 2, 2, 2)); |
|
111 |
return titlePane; |
return titlePane; |
112 |
} |
} |
113 |
|
|
114 |
|
/** |
115 |
|
* Sets the state of the {@link JInternalFrame} to reflect whether or not |
116 |
|
* it is using the palette style. When a frame is displayed as a palette, |
117 |
|
* it uses a different border and the title pane is drawn differently. |
118 |
|
* |
119 |
|
* @param isPalette use the palette style? |
120 |
|
*/ |
121 |
|
public void setPalette(boolean isPalette) |
122 |
|
{ |
123 |
|
MetalInternalFrameTitlePane title = (MetalInternalFrameTitlePane) northPane; |
124 |
|
title.setPalette(isPalette); |
125 |
|
if (isPalette) |
126 |
|
frame.setBorder(new MetalBorders.PaletteBorder()); |
127 |
|
else |
128 |
|
frame.setBorder(new MetalBorders.InternalFrameBorder()); |
129 |
|
} |
130 |
|
|
131 |
|
/** A listener that is used to handle IS_PALETTE property changes. */ |
132 |
|
private PropertyChangeListener paletteListener; |
133 |
|
|
134 |
|
/** |
135 |
|
* Adds the required listeners. |
136 |
|
*/ |
137 |
|
protected void installListeners() |
138 |
|
{ |
139 |
|
super.installListeners(); |
140 |
|
paletteListener = new PropertyChangeListener() |
141 |
|
{ |
142 |
|
public void propertyChange(PropertyChangeEvent e) |
143 |
|
{ |
144 |
|
if (e.getPropertyName().equals(IS_PALETTE)) |
145 |
|
{ |
146 |
|
if (Boolean.TRUE.equals(e.getNewValue())) |
147 |
|
setPalette(true); |
148 |
|
else |
149 |
|
setPalette(false); |
150 |
|
} |
151 |
|
} |
152 |
|
}; |
153 |
|
frame.addPropertyChangeListener(paletteListener); |
154 |
|
} |
155 |
|
|
156 |
|
/** |
157 |
|
* Removes the listeners used. |
158 |
|
*/ |
159 |
|
protected void uninstallListeners() |
160 |
|
{ |
161 |
|
super.uninstallListeners(); |
162 |
|
frame.removePropertyChangeListener(IS_PALETTE, paletteListener); |
163 |
|
paletteListener = null; |
164 |
|
} |
165 |
} |
} |