1 /*
2 * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
134 return getIcon(RADIO_BUTTON_MENU_ITEM_CHECK_ICON);
135 }
136
137 //
138 // ToolBar Handle
139 //
140 public static SynthIcon getToolBarHandleIcon() {
141 return getIcon(TOOL_BAR_HANDLE_ICON);
142 }
143
144 static void resetIcons() {
145 synchronized (iconsPool) {
146 for (DelegatingIcon di: iconsPool.values()) {
147 di.resetIconDimensions();
148 }
149 }
150 }
151
152 private static class DelegatingIcon extends SynthIcon implements
153 UIResource {
154 private static final Class[] PARAM_TYPES = new Class[] {
155 SynthContext.class, Graphics.class, int.class,
156 int.class, int.class, int.class, int.class
157 };
158
159 private Object method;
160 int iconDimension = -1;
161
162 DelegatingIcon(String methodName ){
163 this.method = methodName;
164 }
165
166 public void paintIcon(SynthContext context, Graphics g,
167 int x, int y, int w, int h) {
168 if (context != null) {
169 GTKPainter.INSTANCE.paintIcon(context, g,
170 getMethod(), x, y, w, h);
171 }
172 }
173
174 public int getIconWidth(SynthContext context) {
175 return getIconDimension(context);
176 }
177
178 public int getIconHeight(SynthContext context) {
179 return getIconDimension(context);
180 }
181
182 void resetIconDimensions() {
183 iconDimension = -1;
184 }
185
186 protected Method getMethod() {
187 if (method instanceof String) {
188 method = resolveMethod((String)method);
189 }
190 return (Method)method;
191 }
192
193 protected Class[] getMethodParamTypes() {
194 return PARAM_TYPES;
195 }
196
197 private Method resolveMethod(String name) {
198 try {
199 return GTKPainter.class.getMethod(name, getMethodParamTypes());
200 } catch (NoSuchMethodException e) {
201 assert false;
202 }
203 return null;
204 }
205
206 int getIconDimension(SynthContext context) {
207 if (iconDimension >= 0) {
208 return iconDimension;
209 }
210
211 if (context == null) {
212 return DEFAULT_ICON_SIZE;
213 }
245 }
246
247 int getIconDimension(SynthContext context) {
248 updateSizeIfNecessary(context);
249 return (iconDimension == -1) ? DEFAULT_ICON_SIZE :
250 iconDimension;
251 }
252
253 private void updateSizeIfNecessary(SynthContext context) {
254 if (iconDimension == -1 && context != null) {
255 iconDimension = context.getStyle().getInt(context,
256 "Tree.expanderSize", 10);
257 }
258 }
259 }
260
261 // GTK has a separate widget for the handle box, to mirror this
262 // we create a unique icon per ToolBar and lookup the style for the
263 // HandleBox.
264 private static class ToolBarHandleIcon extends DelegatingIcon {
265 private static final Class[] PARAM_TYPES = new Class[] {
266 SynthContext.class, Graphics.class, int.class,
267 int.class, int.class, int.class, int.class, Orientation.class,
268 };
269
270 private SynthStyle style;
271
272 public ToolBarHandleIcon() {
273 super(TOOL_BAR_HANDLE_ICON);
274 }
275
276 protected Class[] getMethodParamTypes() {
277 return PARAM_TYPES;
278 }
279
280 public void paintIcon(SynthContext context, Graphics g, int x, int y,
281 int w, int h) {
282 if (context != null) {
283 JToolBar toolbar = (JToolBar)context.getComponent();
284 Orientation orientation =
285 (toolbar.getOrientation() == JToolBar.HORIZONTAL ?
286 Orientation.HORIZONTAL : Orientation.VERTICAL);
287
288 if (style == null) {
289 style = SynthLookAndFeel.getStyleFactory().getStyle(
290 context.getComponent(), GTKRegion.HANDLE_BOX);
291 }
292 context = new SynthContext(toolbar, GTKRegion.HANDLE_BOX,
293 style, SynthConstants.ENABLED);
294
295 GTKPainter.INSTANCE.paintIcon(context, g,
296 getMethod(), x, y, w, h, orientation);
306 return 10;
307 } else {
308 return context.getComponent().getWidth();
309 }
310 }
311
312 public int getIconHeight(SynthContext context) {
313 if (context == null) {
314 return 10;
315 }
316 if (((JToolBar)context.getComponent()).getOrientation() ==
317 JToolBar.HORIZONTAL) {
318 return context.getComponent().getHeight();
319 } else {
320 return 10;
321 }
322 }
323 }
324
325 private static class MenuArrowIcon extends DelegatingIcon {
326 private static final Class[] PARAM_TYPES = new Class[] {
327 SynthContext.class, Graphics.class, int.class,
328 int.class, int.class, int.class, int.class, ArrowType.class,
329 };
330
331 public MenuArrowIcon() {
332 super(MENU_ARROW_ICON);
333 }
334
335 protected Class[] getMethodParamTypes() {
336 return PARAM_TYPES;
337 }
338
339 public void paintIcon(SynthContext context, Graphics g, int x, int y,
340 int w, int h) {
341 if (context != null) {
342 ArrowType arrowDir = ArrowType.RIGHT;
343 if (!context.getComponent().getComponentOrientation().isLeftToRight()) {
344 arrowDir = ArrowType.LEFT;
345 }
346 GTKPainter.INSTANCE.paintIcon(context, g,
347 getMethod(), x, y, w, h, arrowDir);
348 }
349 }
350 }
351 }
|
1 /*
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
134 return getIcon(RADIO_BUTTON_MENU_ITEM_CHECK_ICON);
135 }
136
137 //
138 // ToolBar Handle
139 //
140 public static SynthIcon getToolBarHandleIcon() {
141 return getIcon(TOOL_BAR_HANDLE_ICON);
142 }
143
144 static void resetIcons() {
145 synchronized (iconsPool) {
146 for (DelegatingIcon di: iconsPool.values()) {
147 di.resetIconDimensions();
148 }
149 }
150 }
151
152 private static class DelegatingIcon extends SynthIcon implements
153 UIResource {
154 private static final Class<?>[] PARAM_TYPES = new Class<?>[] {
155 SynthContext.class, Graphics.class, int.class,
156 int.class, int.class, int.class, int.class
157 };
158
159 private Object method;
160 int iconDimension = -1;
161
162 DelegatingIcon(String methodName ){
163 this.method = methodName;
164 }
165
166 public void paintIcon(SynthContext context, Graphics g,
167 int x, int y, int w, int h) {
168 if (context != null) {
169 GTKPainter.INSTANCE.paintIcon(context, g,
170 getMethod(), x, y, w, h);
171 }
172 }
173
174 public int getIconWidth(SynthContext context) {
175 return getIconDimension(context);
176 }
177
178 public int getIconHeight(SynthContext context) {
179 return getIconDimension(context);
180 }
181
182 void resetIconDimensions() {
183 iconDimension = -1;
184 }
185
186 protected Method getMethod() {
187 if (method instanceof String) {
188 method = resolveMethod((String)method);
189 }
190 return (Method)method;
191 }
192
193 protected Class<?>[] getMethodParamTypes() {
194 return PARAM_TYPES;
195 }
196
197 private Method resolveMethod(String name) {
198 try {
199 return GTKPainter.class.getMethod(name, getMethodParamTypes());
200 } catch (NoSuchMethodException e) {
201 assert false;
202 }
203 return null;
204 }
205
206 int getIconDimension(SynthContext context) {
207 if (iconDimension >= 0) {
208 return iconDimension;
209 }
210
211 if (context == null) {
212 return DEFAULT_ICON_SIZE;
213 }
245 }
246
247 int getIconDimension(SynthContext context) {
248 updateSizeIfNecessary(context);
249 return (iconDimension == -1) ? DEFAULT_ICON_SIZE :
250 iconDimension;
251 }
252
253 private void updateSizeIfNecessary(SynthContext context) {
254 if (iconDimension == -1 && context != null) {
255 iconDimension = context.getStyle().getInt(context,
256 "Tree.expanderSize", 10);
257 }
258 }
259 }
260
261 // GTK has a separate widget for the handle box, to mirror this
262 // we create a unique icon per ToolBar and lookup the style for the
263 // HandleBox.
264 private static class ToolBarHandleIcon extends DelegatingIcon {
265 private static final Class<?>[] PARAM_TYPES = new Class<?>[] {
266 SynthContext.class, Graphics.class, int.class,
267 int.class, int.class, int.class, int.class, Orientation.class,
268 };
269
270 private SynthStyle style;
271
272 public ToolBarHandleIcon() {
273 super(TOOL_BAR_HANDLE_ICON);
274 }
275
276 protected Class<?>[] getMethodParamTypes() {
277 return PARAM_TYPES;
278 }
279
280 public void paintIcon(SynthContext context, Graphics g, int x, int y,
281 int w, int h) {
282 if (context != null) {
283 JToolBar toolbar = (JToolBar)context.getComponent();
284 Orientation orientation =
285 (toolbar.getOrientation() == JToolBar.HORIZONTAL ?
286 Orientation.HORIZONTAL : Orientation.VERTICAL);
287
288 if (style == null) {
289 style = SynthLookAndFeel.getStyleFactory().getStyle(
290 context.getComponent(), GTKRegion.HANDLE_BOX);
291 }
292 context = new SynthContext(toolbar, GTKRegion.HANDLE_BOX,
293 style, SynthConstants.ENABLED);
294
295 GTKPainter.INSTANCE.paintIcon(context, g,
296 getMethod(), x, y, w, h, orientation);
306 return 10;
307 } else {
308 return context.getComponent().getWidth();
309 }
310 }
311
312 public int getIconHeight(SynthContext context) {
313 if (context == null) {
314 return 10;
315 }
316 if (((JToolBar)context.getComponent()).getOrientation() ==
317 JToolBar.HORIZONTAL) {
318 return context.getComponent().getHeight();
319 } else {
320 return 10;
321 }
322 }
323 }
324
325 private static class MenuArrowIcon extends DelegatingIcon {
326 private static final Class<?>[] PARAM_TYPES = new Class<?>[] {
327 SynthContext.class, Graphics.class, int.class,
328 int.class, int.class, int.class, int.class, ArrowType.class,
329 };
330
331 public MenuArrowIcon() {
332 super(MENU_ARROW_ICON);
333 }
334
335 protected Class<?>[] getMethodParamTypes() {
336 return PARAM_TYPES;
337 }
338
339 public void paintIcon(SynthContext context, Graphics g, int x, int y,
340 int w, int h) {
341 if (context != null) {
342 ArrowType arrowDir = ArrowType.RIGHT;
343 if (!context.getComponent().getComponentOrientation().isLeftToRight()) {
344 arrowDir = ArrowType.LEFT;
345 }
346 GTKPainter.INSTANCE.paintIcon(context, g,
347 getMethod(), x, y, w, h, arrowDir);
348 }
349 }
350 }
351 }
|