75 */ |
75 */ |
76 private static final Object STYLE_FACTORY_KEY = |
76 private static final Object STYLE_FACTORY_KEY = |
77 new StringBuffer("com.sun.java.swing.plaf.gtk.StyleCache"); |
77 new StringBuffer("com.sun.java.swing.plaf.gtk.StyleCache"); |
78 |
78 |
79 /** |
79 /** |
|
80 * AppContext key to get selectedUI. |
|
81 */ |
|
82 private static final Object SELECTED_UI_KEY = new StringBuilder("selectedUI"); |
|
83 |
|
84 /** |
|
85 * AppContext key to get selectedUIState. |
|
86 */ |
|
87 private static final Object SELECTED_UI_STATE_KEY = new StringBuilder("selectedUIState"); |
|
88 |
|
89 /** |
80 * The last SynthStyleFactory that was asked for from AppContext |
90 * The last SynthStyleFactory that was asked for from AppContext |
81 * <code>lastContext</code>. |
91 * <code>lastContext</code>. |
82 */ |
92 */ |
83 private static SynthStyleFactory lastFactory; |
93 private static SynthStyleFactory lastFactory; |
84 /** |
94 /** |
85 * If this is true it indicates there is more than one AppContext active |
|
86 * and that we need to make sure in getStyleCache the requesting |
|
87 * AppContext matches that of <code>lastContext</code> before returning |
|
88 * it. |
|
89 */ |
|
90 private static boolean multipleApps; |
|
91 /** |
|
92 * AppContext lastLAF came from. |
95 * AppContext lastLAF came from. |
93 */ |
96 */ |
94 private static AppContext lastContext; |
97 private static AppContext lastContext; |
95 |
|
96 // Refer to setSelectedUI |
|
97 static ComponentUI selectedUI; |
|
98 // Refer to setSelectedUI |
|
99 static int selectedUIState; |
|
100 |
98 |
101 /** |
99 /** |
102 * SynthStyleFactory for the this SynthLookAndFeel. |
100 * SynthStyleFactory for the this SynthLookAndFeel. |
103 */ |
101 */ |
104 private SynthStyleFactory factory; |
102 private SynthStyleFactory factory; |
108 * method. |
106 * method. |
109 */ |
107 */ |
110 private Map<String, Object> defaultsMap; |
108 private Map<String, Object> defaultsMap; |
111 |
109 |
112 private Handler _handler; |
110 private Handler _handler; |
|
111 |
|
112 static ComponentUI getSelectedUI() { |
|
113 return (ComponentUI) AppContext.getAppContext().get(SELECTED_UI_KEY); |
|
114 } |
113 |
115 |
114 /** |
116 /** |
115 * Used by the renderers. For the most part the renderers are implemented |
117 * Used by the renderers. For the most part the renderers are implemented |
116 * as Labels, which is problematic in so far as they are never selected. |
118 * as Labels, which is problematic in so far as they are never selected. |
117 * To accomodate this SynthLabelUI checks if the current |
119 * To accomodate this SynthLabelUI checks if the current |
120 * a way for labels to have a state other than selected. |
122 * a way for labels to have a state other than selected. |
121 */ |
123 */ |
122 static void setSelectedUI(ComponentUI uix, boolean selected, |
124 static void setSelectedUI(ComponentUI uix, boolean selected, |
123 boolean focused, boolean enabled, |
125 boolean focused, boolean enabled, |
124 boolean rollover) { |
126 boolean rollover) { |
125 selectedUI = uix; |
127 int selectedUIState = 0; |
126 selectedUIState = 0; |
128 |
127 if (selected) { |
129 if (selected) { |
128 selectedUIState = SynthConstants.SELECTED; |
130 selectedUIState = SynthConstants.SELECTED; |
129 if (focused) { |
131 if (focused) { |
130 selectedUIState |= SynthConstants.FOCUSED; |
132 selectedUIState |= SynthConstants.FOCUSED; |
131 } |
133 } |
138 } |
140 } |
139 } |
141 } |
140 else { |
142 else { |
141 if (enabled) { |
143 if (enabled) { |
142 selectedUIState |= SynthConstants.ENABLED; |
144 selectedUIState |= SynthConstants.ENABLED; |
143 selectedUIState = SynthConstants.FOCUSED; |
145 if (focused) { |
|
146 selectedUIState |= SynthConstants.FOCUSED; |
|
147 } |
144 } |
148 } |
145 else { |
149 else { |
146 selectedUIState |= SynthConstants.DISABLED; |
150 selectedUIState |= SynthConstants.DISABLED; |
147 } |
151 } |
148 } |
152 } |
|
153 |
|
154 AppContext context = AppContext.getAppContext(); |
|
155 |
|
156 context.put(SELECTED_UI_KEY, uix); |
|
157 context.put(SELECTED_UI_STATE_KEY, Integer.valueOf(selectedUIState)); |
|
158 } |
|
159 |
|
160 static int getSelectedUIState() { |
|
161 Integer result = (Integer) AppContext.getAppContext().get(SELECTED_UI_STATE_KEY); |
|
162 |
|
163 return result == null ? 0 : result.intValue(); |
149 } |
164 } |
150 |
165 |
151 /** |
166 /** |
152 * Clears out the selected UI that was last set in setSelectedUI. |
167 * Clears out the selected UI that was last set in setSelectedUI. |
153 */ |
168 */ |
154 static void resetSelectedUI() { |
169 static void resetSelectedUI() { |
155 selectedUI = null; |
170 AppContext.getAppContext().remove(SELECTED_UI_KEY); |
156 } |
171 } |
157 |
172 |
158 |
173 |
159 /** |
174 /** |
160 * Sets the SynthStyleFactory that the UI classes provided by |
175 * Sets the SynthStyleFactory that the UI classes provided by |
165 public static void setStyleFactory(SynthStyleFactory cache) { |
180 public static void setStyleFactory(SynthStyleFactory cache) { |
166 // We assume the setter is called BEFORE the getter has been invoked |
181 // We assume the setter is called BEFORE the getter has been invoked |
167 // for a particular AppContext. |
182 // for a particular AppContext. |
168 synchronized(SynthLookAndFeel.class) { |
183 synchronized(SynthLookAndFeel.class) { |
169 AppContext context = AppContext.getAppContext(); |
184 AppContext context = AppContext.getAppContext(); |
170 if (!multipleApps && context != lastContext && |
|
171 lastContext != null) { |
|
172 multipleApps = true; |
|
173 } |
|
174 lastFactory = cache; |
185 lastFactory = cache; |
175 lastContext = context; |
186 lastContext = context; |
176 context.put(STYLE_FACTORY_KEY, cache); |
187 context.put(STYLE_FACTORY_KEY, cache); |
177 } |
188 } |
178 } |
189 } |
182 * |
193 * |
183 * @return SynthStyleFactory |
194 * @return SynthStyleFactory |
184 */ |
195 */ |
185 public static SynthStyleFactory getStyleFactory() { |
196 public static SynthStyleFactory getStyleFactory() { |
186 synchronized(SynthLookAndFeel.class) { |
197 synchronized(SynthLookAndFeel.class) { |
187 if (!multipleApps) { |
|
188 return lastFactory; |
|
189 } |
|
190 AppContext context = AppContext.getAppContext(); |
198 AppContext context = AppContext.getAppContext(); |
191 |
199 |
192 if (lastContext == context) { |
200 if (lastContext == context) { |
193 return lastFactory; |
201 return lastFactory; |
194 } |
202 } |
195 lastContext = context; |
203 lastContext = context; |
196 lastFactory = (SynthStyleFactory)AppContext.getAppContext().get |
204 lastFactory = (SynthStyleFactory) context.get(STYLE_FACTORY_KEY); |
197 (STYLE_FACTORY_KEY); |
|
198 return lastFactory; |
205 return lastFactory; |
199 } |
206 } |
200 } |
207 } |
201 |
208 |
202 /** |
209 /** |