Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/Java/GWT/Client/src/org/litesoft/GWT/client/widgets/nonpublic/ApplyFont.java

Diff revisions: vs.
  @@ -1,67 +1,67 @@
1 - // This Source Code is in the Public Domain per: http://unlicense.org
2 - package org.litesoft.GWT.client.widgets.nonpublic;
3 -
4 - import org.litesoft.uispecification.*;
5 -
6 - import com.google.gwt.user.client.*;
7 - import com.google.gwt.user.client.ui.*;
8 -
9 - public class ApplyFont {
10 - public static Widget to( UiFont pUiFont, Widget pWidget ) {
11 - if ( (pWidget != null) && (pUiFont != null) ) {
12 - to( pUiFont, pWidget.getElement() );
13 - }
14 - return pWidget;
15 - }
16 -
17 - public static void to( UiFont pUiFont, Element pElement ) {
18 - if ( (pElement != null) && (pUiFont != null) ) {
19 - set( pElement, "fontFamily", pUiFont.getFamily(), ",courier" );
20 - set( pElement, "color", pUiFont.getColor() );
21 - set( pElement, "fontSize", pUiFont.getSize() );
22 - set( pElement, "fontStyle", pUiFont.getStyle() );
23 - set( pElement, "fontWeight", pUiFont.getWeight() );
24 - set( pElement, "textDecoration", pUiFont.getDecoration() );
25 - }
26 - }
27 -
28 - public static String toHtmlStyle( UiFont pUiFont ) {
29 - if ( pUiFont != null ) {
30 - StringBuilder sb = new StringBuilder();
31 - set( sb, "font-family", pUiFont.getFamily(), ",courier" );
32 - set( sb, "color", pUiFont.getColor() );
33 - set( sb, "font-size", pUiFont.getSize() );
34 - set( sb, "font-style", pUiFont.getStyle() );
35 - set( sb, "font-weight", pUiFont.getWeight() );
36 - set( sb, "text-decoration", pUiFont.getDecoration() );
37 - if ( sb.length() != 0 ) {
38 - return " style=\"" + sb.toString() + "\"";
39 - }
40 - }
41 - return "";
42 - }
43 -
44 - private static void set( StringBuilder pSB, String pAttributeName, String pValue, String pAdditionalIfNotNull ) {
45 - if ( pValue != null ) {
46 - set( pSB, pAttributeName, pValue + pAdditionalIfNotNull );
47 - }
48 - }
49 -
50 - private static void set( StringBuilder pSB, String pAttributeName, String pValue ) {
51 - if ( pValue != null ) {
52 - pSB.append( pAttributeName ).append( ':' ).append( pValue ).append( ';' );
53 - }
54 - }
55 -
56 - private static void set( Element pElement, String pAttributeName, String pValue, String pAdditionalIfNotNull ) {
57 - if ( pValue != null ) {
58 - set( pElement, pAttributeName, pValue + pAdditionalIfNotNull );
59 - }
60 - }
61 -
62 - private static void set( Element pElement, String pAttributeName, String pValue ) {
63 - if ( pValue != null ) {
64 - DOM.setStyleAttribute( pElement, pAttributeName, pValue );
65 - }
66 - }
67 - }
1 + // This Source Code is in the Public Domain per: http://unlicense.org
2 + package org.litesoft.GWT.client.widgets.nonpublic;
3 +
4 + import org.litesoft.uispecification.*;
5 +
6 + import com.google.gwt.user.client.*;
7 + import com.google.gwt.user.client.ui.*;
8 +
9 + public class ApplyFont {
10 + public static Widget to( UiFont pUiFont, Widget pWidget ) {
11 + if ( (pWidget != null) && (pUiFont != null) ) {
12 + to( pUiFont, pWidget.getElement() );
13 + }
14 + return pWidget;
15 + }
16 +
17 + public static void to( UiFont pUiFont, Element pElement ) {
18 + if ( (pElement != null) && (pUiFont != null) ) {
19 + set( pElement, "fontFamily", pUiFont.getFamily(), ",courier" );
20 + set( pElement, "color", pUiFont.getColor() );
21 + set( pElement, "fontSize", pUiFont.getSize() );
22 + set( pElement, "fontStyle", pUiFont.getStyle() );
23 + set( pElement, "fontWeight", pUiFont.getWeight() );
24 + set( pElement, "textDecoration", pUiFont.getDecoration() );
25 + }
26 + }
27 +
28 + public static String toHtmlStyle( UiFont pUiFont ) {
29 + if ( pUiFont != null ) {
30 + StringBuilder sb = new StringBuilder();
31 + set( sb, "font-family", pUiFont.getFamily(), ",courier" );
32 + set( sb, "color", pUiFont.getColor() );
33 + set( sb, "font-size", pUiFont.getSize() );
34 + set( sb, "font-style", pUiFont.getStyle() );
35 + set( sb, "font-weight", pUiFont.getWeight() );
36 + set( sb, "text-decoration", pUiFont.getDecoration() );
37 + if ( sb.length() != 0 ) {
38 + return " style=\"" + sb.toString() + "\"";
39 + }
40 + }
41 + return "";
42 + }
43 +
44 + private static void set( StringBuilder pSB, String pAttributeName, String pValue, String pAdditionalIfNotNull ) {
45 + if ( pValue != null ) {
46 + set( pSB, pAttributeName, pValue + pAdditionalIfNotNull );
47 + }
48 + }
49 +
50 + private static void set( StringBuilder pSB, String pAttributeName, String pValue ) {
51 + if ( pValue != null ) {
52 + pSB.append( pAttributeName ).append( ':' ).append( pValue ).append( ';' );
53 + }
54 + }
55 +
56 + private static void set( Element pElement, String pAttributeName, String pValue, String pAdditionalIfNotNull ) {
57 + if ( pValue != null ) {
58 + set( pElement, pAttributeName, pValue + pAdditionalIfNotNull );
59 + }
60 + }
61 +
62 + private static void set( Element pElement, String pAttributeName, String pValue ) {
63 + if ( pValue != null ) {
64 + DOM.setStyleAttribute( pElement, pAttributeName, pValue );
65 + }
66 + }
67 + }