Source Code Cross Referenced for SubstanceSizeUtils.java in  » Swing-Library » substance-look-feel » org » jvnet » substance » utils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » substance look feel » org.jvnet.substance.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003:         *
004:         * Redistribution and use in source and binary forms, with or without 
005:         * modification, are permitted provided that the following conditions are met:
006:         * 
007:         *  o Redistributions of source code must retain the above copyright notice, 
008:         *    this list of conditions and the following disclaimer. 
009:         *     
010:         *  o Redistributions in binary form must reproduce the above copyright notice, 
011:         *    this list of conditions and the following disclaimer in the documentation 
012:         *    and/or other materials provided with the distribution. 
013:         *     
014:         *  o Neither the name of Substance Kirill Grouchnikov nor the names of 
015:         *    its contributors may be used to endorse or promote products derived 
016:         *    from this software without specific prior written permission. 
017:         *     
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
020:         * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
021:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
022:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
023:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
025:         * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
026:         * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
027:         * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
028:         * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
029:         */
030:        package org.jvnet.substance.utils;
031:
032:        import java.awt.*;
033:
034:        import javax.swing.border.Border;
035:        import javax.swing.plaf.BorderUIResource;
036:
037:        import org.jvnet.substance.SubstanceLookAndFeel;
038:        import org.jvnet.substance.button.ClassicButtonShaper;
039:        import org.jvnet.substance.fonts.*;
040:
041:        /**
042:         * This class is responsible for computing DPI-aware insets, stroke widths,
043:         * paddings, icon sizes etc.
044:         * 
045:         * @author Kirill Grouchnikov
046:         */
047:        public class SubstanceSizeUtils {
048:            /**
049:             * Cached control font size.
050:             */
051:            private static int controlFontSize = -1;
052:
053:            private static double pointsToPixelsRatio = 1.0;
054:
055:            /**
056:             * Gets the current control font size.
057:             * 
058:             * @return Control font size.
059:             */
060:            public static int getControlFontSize() {
061:                if (controlFontSize > 0)
062:                    return controlFontSize;
063:                FontPolicy fPolicy = SubstanceLookAndFeel.getFontPolicy();
064:                FontSet fSet = fPolicy.getFontSet("Substance", null);
065:                controlFontSize = fSet.getControlFont().getSize();
066:                return controlFontSize;
067:            }
068:
069:            /**
070:             * Sets the new value for the control font size.
071:             * 
072:             * @param size
073:             *            Control font size.
074:             */
075:            public static void setControlFontSize(int size) {
076:                controlFontSize = size;
077:            }
078:
079:            /**
080:             * Computes the font size for the specified component. If the component is
081:             * <code>null</code> or doesn't have font set ({@link Component#getFont()}
082:             * returns <code>null</code>), this method returns the default control
083:             * font size from {@link #getControlFontSize()}.
084:             * 
085:             * @param c
086:             *            Component.
087:             * @return Font size for the specified component
088:             */
089:            public static int getComponentFontSize(Component c) {
090:                return ((c == null) || (c.getFont() == null)) ? getControlFontSize()
091:                        : c.getFont().getSize();
092:            }
093:
094:            /**
095:             * Gets the adjusted size. The basic functionality of this method is as
096:             * follows:
097:             * 
098:             * <ul>
099:             * <li>The <code>baseSize</code> parameter specifies the base value</li>
100:             * <li>The <code>forEachBase</code> and <code>toAdjustBy</code> specify
101:             * how to adjust the resulting value based on the passed
102:             * <code>fontSize</code>.</li>
103:             * </ul>
104:             * 
105:             * For example, if you want base value to be 1.2 pixels, and have it grow by
106:             * 0.1 pixel for every additional pixel in the font size, call this method
107:             * with the following values:
108:             * 
109:             * <ul>
110:             * <li><code>baseSize</code> = 1.2</li>
111:             * <li><code>forEachBase</code> = 1</li>
112:             * <li><code>toAdjustBy</code> = 0.1</li>
113:             * </ul>
114:             * 
115:             * @param fontSize
116:             *            Font size.
117:             * @param baseSize
118:             *            The base value.
119:             * @param forEachBase
120:             *            Base units for computing the adjustment.
121:             * @param toAdjustBy
122:             *            Adjustment amount for computing the adjustment.
123:             * @return Adjusted size.
124:             */
125:            public static float getAdjustedSize(int fontSize, float baseSize,
126:                    int forEachBase, float toAdjustBy) {
127:                int delta = fontSize - 11;
128:                if (delta <= 0)
129:                    return baseSize;
130:                float result = baseSize + delta * toAdjustBy / forEachBase;
131:                return result;
132:            }
133:
134:            /**
135:             * Gets the adjusted size. The basic functionality of this method is as
136:             * follows:
137:             * 
138:             * <ul>
139:             * <li>The <code>baseSize</code> parameter specifies the base value</li>
140:             * <li>The <code>forEachBase</code> and <code>toAdjustBy</code> specify
141:             * how to adjust the resulting value based on the passed
142:             * <code>fontSize</code>.</li>
143:             * </ul>
144:             * 
145:             * For example, if you want base value to be 4 pixels, and have it grow by 1
146:             * pixel for every 3 additional pixels in the font size, call this method
147:             * with the following values:
148:             * 
149:             * <ul>
150:             * <li><code>baseSize</code> = 4</li>
151:             * <li><code>forEachBase</code> = 3</li>
152:             * <li><code>toAdjustBy</code> = 1</li>
153:             * </ul>
154:             * 
155:             * @param fontSize
156:             *            Font size.
157:             * @param baseSize
158:             *            The base value.
159:             * @param forEachBase
160:             *            Base units for computing the adjustment.
161:             * @param toAdjustBy
162:             *            Adjustment amount for computing the adjustment.
163:             * @param toRoundAsEven
164:             *            If <code>true</code>, the final value will be rounded down
165:             *            to the closest even value.
166:             * @return Adjusted size.
167:             */
168:            public static int getAdjustedSize(int fontSize, int baseSize,
169:                    int forEachBase, int toAdjustBy, boolean toRoundAsEven) {
170:                int delta = fontSize - 11;
171:                if (delta <= 0)
172:                    return baseSize;
173:                int result = baseSize + delta * toAdjustBy / forEachBase;
174:                if (toRoundAsEven && (result % 2 == 1))
175:                    result--;
176:                return result;
177:            }
178:
179:            /**
180:             * Returns the height of arrow icons under the specified font size.
181:             * 
182:             * @param fontSize
183:             *            Font size.
184:             * @return Height of arrow icons under the specified font size.
185:             */
186:            public static int getArrowIconHeight(int fontSize) {
187:                return 6 + (fontSize - 11) / 3;
188:            }
189:
190:            /**
191:             * Returns the width of arrow icons under the specified font size.
192:             * 
193:             * @param fontSize
194:             *            Font size.
195:             * @return Width of arrow icons under the specified font size.
196:             */
197:            public static int getArrowIconWidth(int fontSize) {
198:                int result = fontSize
199:                        - (int) (2 * getBorderStrokeWidth(fontSize));
200:                if (result % 2 == 0)
201:                    result--;
202:                return result;
203:            }
204:
205:            /**
206:             * Returns the stroke width of arrow icons under the specified font size.
207:             * 
208:             * @param fontSize
209:             *            Font size.
210:             * @return Stroke width of arrow icons under the specified font size.
211:             */
212:            public static float getArrowStrokeWidth(int fontSize) {
213:                return fontSize / 6.0f;
214:            }
215:
216:            /**
217:             * Returns the stroke width of borders under the specified font size.
218:             * 
219:             * @param fontSize
220:             *            Font size.
221:             * @return Stroke width of borders under the specified font size.
222:             */
223:            public static float getBorderStrokeWidth(int fontSize) {
224:                return fontSize / 10.0f;
225:            }
226:
227:            /**
228:             * Returns the border for check boxes under the specified font size.
229:             * 
230:             * @param fontSize
231:             *            Font size.
232:             * @return Border for check boxes under the specified font size.
233:             */
234:            public static Border getCheckBoxBorder(int fontSize) {
235:                int focusRingWidth = (int) Math.ceil(2.0 * SubstanceSizeUtils
236:                        .getFocusStrokeWidth(fontSize));
237:                int tbInset = 1 + focusRingWidth;
238:                int lrInset = focusRingWidth;
239:                return new BorderUIResource.EmptyBorderUIResource(tbInset,
240:                        lrInset, tbInset, 2 + lrInset);
241:            }
242:
243:            /**
244:             * Returns the check mark size for check boxes under the specified font
245:             * size.
246:             * 
247:             * @param fontSize
248:             *            Font size.
249:             * @return Check mark size for check boxes under the specified font size.
250:             */
251:            public static int getCheckBoxMarkSize(int fontSize) {
252:                return 5 + fontSize;
253:            }
254:
255:            /**
256:             * Returns the corner radius for {@link ClassicButtonShaper} under the
257:             * specified font size.
258:             * 
259:             * @param fontSize
260:             *            Font size.
261:             * @return Corner radius for {@link ClassicButtonShaper} under the specified
262:             *         font size.
263:             */
264:            public static float getClassicButtonCornerRadius(int fontSize) {
265:                return getAdjustedSize(fontSize, 2, 6, 1, false);
266:            }
267:
268:            /**
269:             * Returns the combo box border insets under the specified font size.
270:             * 
271:             * @param fontSize
272:             *            Font size.
273:             * @return Combo box border insets under the specified font size.
274:             */
275:            public static Insets getComboBorderInsets(int fontSize) {
276:                // The base insets are 1,2,1,2. We add one pixel for
277:                // each 4 extra points in base control size.
278:                int tbInset = getAdjustedSize(fontSize, 1, 4, 1, false);
279:                int lrInset = getAdjustedSize(fontSize, 2, 4, 1, false);
280:                return new Insets(tbInset, lrInset, tbInset, lrInset);
281:            }
282:
283:            /**
284:             * Returns the combo box text border insets under the specified font size.
285:             * 
286:             * @param fontSize
287:             *            Font size.
288:             * @return Combo box text border insets under the specified font size.
289:             */
290:            public static Insets getComboTextBorderInsets(int fontSize) {
291:                // the following makes sure that the text components
292:                // and combos have the same height and text alignment
293:                // under all font sizes.
294:                Insets textInsets = getTextBorderInsets(fontSize);
295:                Insets comboInsets = getComboBorderInsets(fontSize);
296:                int topDelta = textInsets.top - comboInsets.top;
297:                int bottomDelta = textInsets.bottom - comboInsets.bottom;
298:
299:                int lrInset = getAdjustedSize(fontSize, 1, 4, 1, false);
300:                return new Insets(topDelta, lrInset, bottomDelta, lrInset);
301:            }
302:
303:            /**
304:             * Returns the default border insets under the specified font size.
305:             * 
306:             * @param fontSize
307:             *            Font size.
308:             * @return Default border insets under the specified font size.
309:             */
310:            public static Insets getDefaultBorderInsets(int fontSize) {
311:                // The base insets are 2,2,2,2. We add one pixel for
312:                // each 3 extra points in base control size.
313:                int inset = getAdjustedSize(fontSize, 2, 3, 1, false);
314:                return new Insets(inset, inset, inset, inset);
315:            }
316:
317:            /**
318:             * Returns the stroke width of double arrow icons under the specified font
319:             * size.
320:             * 
321:             * @param fontSize
322:             *            Font size.
323:             * @return Stroke width of double arrow icons under the specified font size.
324:             */
325:            public static float getDoubleArrowStrokeWidth(int fontSize) {
326:                return fontSize / 8.0f;
327:            }
328:
329:            /**
330:             * Returns the diameter of a drag bump dot under the specified font size.
331:             * 
332:             * @param fontSize
333:             *            Font size.
334:             * @return Diameter of a drag bump dot under the specified font size.
335:             */
336:            public static int getDragBumpDiameter(int fontSize) {
337:                return getAdjustedSize(fontSize, 2, 4, 1, false);
338:            }
339:
340:            /**
341:             * Returns the diameter of a big drag bump dot under the specified font
342:             * size.
343:             * 
344:             * @param fontSize
345:             *            Font size.
346:             * @return Diameter of a big drag bump dot under the specified font size.
347:             */
348:            public static int getBigDragBumpDiameter(int fontSize) {
349:                int result = getAdjustedSize(fontSize, 3, 3, 1, false);
350:                if (result % 2 == 1)
351:                    result++;
352:                return result;
353:            }
354:
355:            /**
356:             * Returns the extra padding amount under the specified font size.
357:             * 
358:             * @param fontSize
359:             *            Font size.
360:             * @return Extra padding amount under the specified font size.
361:             */
362:            public static int getExtraPadding(int fontSize) {
363:                if (fontSize < 14)
364:                    return 0;
365:                return (fontSize - 11) / 3;
366:            }
367:
368:            /**
369:             * Returns the stroke width of focus rings under the specified font size.
370:             * 
371:             * @param fontSize
372:             *            Font size.
373:             * @return Stroke width of focus rings under the specified font size.
374:             */
375:            public static float getFocusStrokeWidth(int fontSize) {
376:                return Math.max(1.0f, fontSize / 10.0f);
377:            }
378:
379:            /**
380:             * Returns the list cell renderer insets under the specified font size.
381:             * 
382:             * @param fontSize
383:             *            Font size.
384:             * @return List cell renderer insets under the specified font size.
385:             */
386:            public static Insets getListCellRendererInsets(int fontSize) {
387:                // Special handling to make non-editable combo boxes
388:                // have the same height as text components. The combo box
389:                // uses list cell renderer, so to compute the top and
390:                // bottom insets of a list cell renderer, we subtract the
391:                // insets of combo box from the insets of text component.
392:                Insets textInsets = getTextBorderInsets(fontSize);
393:                Insets comboInsets = getComboBorderInsets(fontSize);
394:                int topDelta = textInsets.top - comboInsets.top;
395:                int bottomDelta = textInsets.bottom - comboInsets.bottom;
396:
397:                int lrInset = SubstanceSizeUtils.getAdjustedSize(fontSize, 4,
398:                        4, 1, false);
399:                return new Insets(topDelta, lrInset, bottomDelta, lrInset);
400:            }
401:
402:            /**
403:             * Returns the check mark size of check box menu items and radio button menu
404:             * items under the specified font size.
405:             * 
406:             * @param fontSize
407:             *            Font size.
408:             * @return Check mark size of check box menu items and radio button menu
409:             *         items under the specified font size.
410:             */
411:            public static int getMenuCheckMarkSize(int fontSize) {
412:                int result = fontSize - 2;
413:                if (result % 2 == 0)
414:                    result--;
415:                return result;
416:            }
417:
418:            /**
419:             * Returns the margin for menu items under the specified font size.
420:             * 
421:             * @param fontSize
422:             *            Font size.
423:             * @return Margin for menu items under the specified font size.
424:             */
425:            public static int getMenuItemMargin(int fontSize) {
426:                return getAdjustedSize(fontSize, 2, 4, 1, false);
427:            }
428:
429:            /**
430:             * Returns the gap between text and icon in menu items under the specified
431:             * font size.
432:             * 
433:             * @param fontSize
434:             *            Font size.
435:             * @return Gap between text and icon in menu items under the specified font
436:             *         size.
437:             */
438:            public static int getMenuTextIconGap(int fontSize) {
439:                return getAdjustedSize(fontSize, 4, 3, 1, false);
440:            }
441:
442:            /**
443:             * Returns the minimum button height under the specified font size.
444:             * 
445:             * @param fontSize
446:             *            Font size.
447:             * @return Minimum button height under the specified font size.
448:             */
449:            public static int getMinButtonHeight(int fontSize) {
450:                return 11 + (fontSize - 5) * 3 / 2;
451:            }
452:
453:            /**
454:             * Returns the maximum button height under the specified font size.
455:             * 
456:             * @param fontSize
457:             *            Font size.
458:             * @return Maximum button height under the specified font size.
459:             */
460:            public static int getMinButtonWidth(int fontSize) {
461:                return (int) (3.5 * getMinButtonHeight(fontSize));
462:            }
463:
464:            /**
465:             * Returns the password dot diameter for password fields under the specified
466:             * font size.
467:             * 
468:             * @param fontSize
469:             *            Font size.
470:             * @return Password dot diameter for password fields under the specified
471:             *         font size.
472:             */
473:            public static int getPasswordDotDiameter(int fontSize) {
474:                return getAdjustedSize(fontSize, 7, 2, 1, false);
475:            }
476:
477:            /**
478:             * Returns the password dot gap for password fields under the specified font
479:             * size.
480:             * 
481:             * @param fontSize
482:             *            Font size.
483:             * @return Password dot gap for password fields under the specified font
484:             *         size.
485:             */
486:            public static int getPasswordDotGap(int fontSize) {
487:                return (fontSize - 6) / 3;
488:            }
489:
490:            /**
491:             * Returns the border for radio buttons under the specified font size.
492:             * 
493:             * @param fontSize
494:             *            Font size.
495:             * @return Border for radio buttons under the specified font size.
496:             */
497:            public static Border getRadioButtonBorder(int fontSize) {
498:                int focusRingWidth = (int) Math.ceil(2.0 * SubstanceSizeUtils
499:                        .getFocusStrokeWidth(fontSize));
500:                int tbInset = 1 + focusRingWidth;
501:                int lrInset = focusRingWidth;
502:                return new BorderUIResource.EmptyBorderUIResource(tbInset,
503:                        3 + lrInset, tbInset, 2 + lrInset);
504:            }
505:
506:            /**
507:             * Returns the check mark size for radio buttons under the specified font
508:             * size.
509:             * 
510:             * @param fontSize
511:             *            Font size.
512:             * @return Check mark size for radio buttons under the specified font size.
513:             */
514:            public static int getRadioButtonMarkSize(int fontSize) {
515:                int result = fontSize;
516:                if (result % 2 == 0)
517:                    result--;
518:                return result;
519:            }
520:
521:            /**
522:             * Returns the width of scroll bars under the specified font size.
523:             * 
524:             * @param fontSize
525:             *            Font size.
526:             * @return Width of scroll bars under the specified font size.
527:             */
528:            public static int getScrollBarWidth(int fontSize) {
529:                return fontSize + 4;
530:            }
531:
532:            /**
533:             * Returns the slider thumb icon size under the specified font size.
534:             * 
535:             * @param fontSize
536:             *            Font size.
537:             * @return Slider thumb icon size under the specified font size.
538:             */
539:            public static int getSliderIconSize(int fontSize) {
540:                int result = fontSize + 5;
541:                if (result % 2 == 1)
542:                    result--;
543:                return result;
544:            }
545:
546:            /**
547:             * Returns the slider tick size under the specified font size.
548:             * 
549:             * @param fontSize
550:             *            Font size.
551:             * @return Slider tick size under the specified font size.
552:             */
553:            public static int getSliderTickSize(int fontSize) {
554:                return Math.max(7, fontSize - 3);
555:            }
556:
557:            /**
558:             * Returns the slider track size under the specified font size.
559:             * 
560:             * @param fontSize
561:             *            Font size.
562:             * @return Slider track size under the specified font size.
563:             */
564:            public static int getSliderTrackSize(int fontSize) {
565:                return Math.max(4, 5 + (fontSize - 11) / 2);
566:            }
567:
568:            /**
569:             * Returns the spinner border insets under the specified font size.
570:             * 
571:             * @param fontSize
572:             *            Font size.
573:             * @return Spinner border insets under the specified font size.
574:             */
575:            public static Insets getSpinnerBorderInsets(int fontSize) {
576:                // make sure that spinners and combos have the same height and text
577:                // alignment under all font sizes.
578:                Insets comboInsets = getComboBorderInsets(fontSize);
579:                return new Insets(comboInsets.top + 1, comboInsets.left,
580:                        comboInsets.bottom + 1, comboInsets.right);
581:            }
582:
583:            /**
584:             * Returns the spinner arrow button insets under the specified font size.
585:             * 
586:             * @param fontSize
587:             *            Font size.
588:             * @return Spinner arrow button insets under the specified font size.
589:             */
590:            public static Insets getSpinnerArrowButtonInsets(int fontSize) {
591:                int borderStrokeWidth = (int) Math
592:                        .floor(getBorderStrokeWidth(fontSize));
593:                return new Insets(borderStrokeWidth, borderStrokeWidth,
594:                        borderStrokeWidth, borderStrokeWidth);
595:            }
596:
597:            /**
598:             * Returns the spinner button width under the specified font size.
599:             * 
600:             * @param fontSize
601:             *            Font size.
602:             * @return Spinner button width under the specified font size.
603:             */
604:            public static int getSpinnerButtonWidth(int fontSize) {
605:                return getArrowIconWidth(fontSize) * 3 / 2;
606:            }
607:
608:            /**
609:             * Returns the spinner text border insets under the specified font size.
610:             * 
611:             * @param fontSize
612:             *            Font size.
613:             * @return Spinner text border insets under the specified font size.
614:             */
615:            public static Insets getSpinnerTextBorderInsets(int fontSize) {
616:                Insets textInsets = getComboTextBorderInsets(fontSize);
617:                return new Insets(textInsets.top - 1, textInsets.left,
618:                        textInsets.bottom - 1, textInsets.right);
619:            }
620:
621:            /**
622:             * Returns the tabbed pane content insets under the specified size. The
623:             * {@link SubstanceConstants.TabContentPaneBorderKind#SINGLE_FULL} is
624:             * assumed.
625:             * 
626:             * @param fontSize
627:             *            Font size.
628:             * @return Tabbed pane content insets under the specified size.
629:             */
630:            public static Insets getTabbedPaneContentInsets(int fontSize) {
631:                float borderStrokeWidth = getBorderStrokeWidth(fontSize);
632:                int tbIns = (int) (Math.ceil(2.5 * borderStrokeWidth));
633:                int lrIns = (int) (Math.ceil(3.0 * borderStrokeWidth));
634:                return new Insets(tbIns, lrIns, tbIns, lrIns);
635:            }
636:
637:            /**
638:             * Returns the stroke width of tab close buttons under the specified size.
639:             * 
640:             * @param fontSize
641:             *            Font size.
642:             * @return Stroke width of tab close buttons under the specified size.
643:             */
644:            public static float getTabCloseButtonStrokeWidth(int fontSize) {
645:                return fontSize / 10.0f;
646:            }
647:
648:            /**
649:             * Returns the icon size of tab close buttons under the specified size.
650:             * 
651:             * @param fontSize
652:             *            Font size.
653:             * @return Icon size of tab close buttons under the specified size.
654:             */
655:            public static int getTabCloseIconSize(int fontSize) {
656:                return fontSize - 2;
657:            }
658:
659:            /**
660:             * Returns the table cell renderer insets under the specified font size.
661:             * 
662:             * @param fontSize
663:             *            Font size.
664:             * @return Table cell renderer insets under the specified font size.
665:             */
666:            public static Insets getTableCellRendererInsets(int fontSize) {
667:                Insets listCellInsets = getListCellRendererInsets(fontSize);
668:                return new Insets(listCellInsets.top - 1,
669:                        listCellInsets.left - 2, listCellInsets.bottom - 1,
670:                        listCellInsets.right - 2);
671:            }
672:
673:            /**
674:             * Returns the text border insets under the specified font size.
675:             * 
676:             * @param fontSize
677:             *            Font size.
678:             * @return Text border insets under the specified font size.
679:             */
680:            public static Insets getTextBorderInsets(int fontSize) {
681:                // The base insets are 3,4,3,4. We add one pixel for
682:                // each 3 extra points in base control size.
683:                int tbInset = getAdjustedSize(fontSize, 3, 3, 1, false);
684:                int lrInset = getAdjustedSize(fontSize, 4, 3, 1, false);
685:                return new Insets(tbInset, lrInset, tbInset, lrInset);
686:            }
687:
688:            /**
689:             * Returns the icon size of title pane buttons under the specified size.
690:             * 
691:             * @param fontSize
692:             *            Font size.
693:             * @return Icon size of title pane buttons under the specified size.
694:             */
695:            public static int getTitlePaneIconSize() {
696:                return 5 + getControlFontSize();
697:            }
698:
699:            /**
700:             * Returns the tool bar drag inset under the specified font size.
701:             * 
702:             * @param fontSize
703:             *            Font size.
704:             * @return Tool bar drag inset under the specified font size.
705:             */
706:            public static int getToolBarDragInset(int fontSize) {
707:                return fontSize + 5;
708:            }
709:
710:            /**
711:             * Returns the tool bar insets under the specified font size.
712:             * 
713:             * @param fontSize
714:             *            Font size.
715:             * @return Tool bar insets under the specified font size.
716:             */
717:            public static Insets getToolBarInsets(int fontSize) {
718:                int lbrInset = getAdjustedSize(fontSize, 2, 3, 1, false);
719:                int tInset = getAdjustedSize(fontSize, 1, 3, 1, false);
720:                return new Insets(tInset, lbrInset, lbrInset, lbrInset);
721:            }
722:
723:            /**
724:             * Returns the icon size of tree expand / collapse icons under the specified
725:             * size.
726:             * 
727:             * @param fontSize
728:             *            Font size.
729:             * @return Icon size of tree expand / collapse icons under the specified
730:             *         size.
731:             */
732:            public static int getTreeIconSize(int fontSize) {
733:                int extraPadding = SubstanceSizeUtils.getExtraPadding(fontSize);
734:                int extraPadding2 = 2 * extraPadding;
735:                return 10 + extraPadding2;
736:            }
737:
738:            public static double getPointsToPixelsRatio() {
739:                return pointsToPixelsRatio;
740:            }
741:
742:            public static void resetPointsToPixelsRatio(FontPolicy fontPolicy) {
743:                if (fontPolicy instanceof  DefaultGnomeFontPolicy) {
744:                    pointsToPixelsRatio = DefaultGnomeFontPolicy
745:                            .getPointsToPixelsRatio();
746:                } else {
747:                    pointsToPixelsRatio = Toolkit.getDefaultToolkit()
748:                            .getScreenResolution() / 72.0;
749:                }
750:            }
751:
752:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.