Subversion Repository Public Repository

litesoft

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

Diff revisions: vs.
  @@ -1,186 +1,186 @@
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.GWT.client.widgets.*;
5 - import org.litesoft.commonfoundation.typeutils.Objects;
6 - import org.litesoft.commonfoundation.typeutils.gregorian.*;
7 - import org.litesoft.core.simpletypes.temporal.*;
8 - import org.litesoft.ui.support.nonpublic.*;
9 -
10 - import com.google.gwt.user.client.ui.*;
11 -
12 - import java.util.*;
13 -
14 - public class CreditsPanel
15 - extends SizeableSimplePanel {
16 - public CreditsPanel( CreditsData[] pCreditsData ) {
17 - super( false );
18 -
19 - setWidget( new HTML( createHTML( pCreditsData ) ) );
20 - addStyleName( "litesoft-CreditsFixedFont" );
21 - }
22 -
23 - private String createHTML( CreditsData[] pCreditsData ) {
24 - if ( Objects.isNullOrEmpty( pCreditsData ) ) {
25 - return "";
26 - }
27 -
28 - int longestWhoLength = 2;
29 - CalendarYMD earliestStartDate = pCreditsData[0].getStartDate();
30 - CalendarYMD latestEndDate = pCreditsData[0].getEndDate();
31 - for ( int i = 0; i < pCreditsData.length; i++ ) {
32 - CreditsData creditsData = pCreditsData[i];
33 - int whoLength = creditsData.getWho().length();
34 - CalendarYMD startDate = creditsData.getStartDate();
35 - CalendarYMD endDate = creditsData.getEndDate();
36 - while ( whoLength > longestWhoLength ) {
37 - longestWhoLength += 2;
38 - }
39 - if ( !startDate.afterOrEqual( earliestStartDate ) ) {
40 - earliestStartDate = startDate;
41 - }
42 - if ( !endDate.beforeOrEqual( latestEndDate ) ) {
43 - latestEndDate = endDate;
44 - }
45 - }
46 - longestWhoLength += 3;
47 - Arrays.sort( pCreditsData );
48 - HtmlBuilder builder = new HtmlBuilder( "litesoft-CreditsColorized" );
49 -
50 - // Add Header
51 - for ( int i = longestWhoLength; i > 0; i-- ) {
52 - builder.addNBSP();
53 - }
54 - CreditsData.MonthYear zMY = new CreditsData.MonthYear( earliestStartDate );
55 - do {
56 - builder.addNBSP();
57 - builder.add( zMY.toString() );
58 - }
59 - while ( zMY.incMonth().isLessThanOrEqual( latestEndDate ) );
60 - builder.newLine();
61 -
62 - // Add Seperator
63 - for ( int i = longestWhoLength; i > 0; i-- ) {
64 - builder.add( '-' );
65 - }
66 - zMY = new CreditsData.MonthYear( earliestStartDate );
67 - do {
68 - builder.add( '-' );
69 - builder.add( '+' );
70 - builder.add( '-' );
71 - builder.add( '-' );
72 - builder.add( '-' );
73 - builder.add( '-' );
74 - }
75 - while ( zMY.incMonth().isLessThanOrEqual( latestEndDate ) );
76 - builder.add( '-' );
77 - builder.newLine();
78 -
79 - for ( int i = 0; i < pCreditsData.length; i++ ) {
80 - CreditsData creditsData = pCreditsData[i];
81 - builder.add( creditsData.getWho(), longestWhoLength );
82 - builder.addNBSP();
83 - zMY = new CreditsData.MonthYear( earliestStartDate );
84 - do {
85 - int year = zMY.getYear();
86 - int month = zMY.getMonth();
87 - int daysInMonth = Month.daysIn( year, month );
88 - int lastSplit = (daysInMonth + 18) / 2;
89 - builder.colorize( creditsData.wasActiveDuring( year, month, 1, 6 ) );
90 - builder.add( '|' ); // 1
91 - builder.colorize( creditsData.wasActiveDuring( year, month, 7, 12 ) );
92 - builder.addNBSP(); // 2
93 - builder.colorize( creditsData.wasActiveDuring( year, month, 13, 18 ) );
94 - builder.add( '.' ); // 3
95 - builder.colorize( creditsData.wasActiveDuring( year, month, 19, lastSplit ) );
96 - builder.addNBSP(); // 4
97 - builder.colorize( creditsData.wasActiveDuring( year, month, lastSplit + 1, daysInMonth ) );
98 - builder.add( '.' ); // 5
99 - zMY.incMonth();
100 - builder.colorize( creditsData.wasActiveDuring( zMY.getYear(), zMY.getMonth(), 1, 1 ) );
101 - builder.addNBSP(); // 6
102 - }
103 - while ( zMY.isLessThanOrEqual( latestEndDate ) );
104 - builder.newLine();
105 - }
106 - //To change body of created methods use File | Settings | File Templates.
107 - return builder.toString();
108 - }
109 -
110 - private static class HtmlBuilder {
111 - private StringBuilder mSB = new StringBuilder();
112 - private boolean mColorize = false;
113 - private String mColorStyle;
114 - private int mOffset = 0;
115 -
116 - public HtmlBuilder( String pColorStyle ) {
117 - mColorStyle = pColorStyle;
118 - }
119 -
120 - public void colorize( boolean pColorize ) {
121 - mColorize = pColorize;
122 - }
123 -
124 - public void newLine() {
125 - mColorize = false;
126 - mSB.append( "<br>" );
127 - mOffset = 0;
128 - }
129 -
130 - private void LLaddChar( String pChar ) {
131 - if ( mColorize ) {
132 - mSB.append( "<span class='" ).append( mColorStyle ).append( "'>" );
133 - mSB.append( pChar );
134 - mSB.append( "</span>" );
135 - } else {
136 - mSB.append( pChar );
137 - }
138 - mOffset++;
139 - }
140 -
141 - public void addNBSP() {
142 - LLaddChar( "&nbsp;" );
143 - }
144 -
145 - public void addSP() {
146 - if ( mColorize || ((mOffset & 1) == 1) ) {
147 - addNBSP();
148 - } else {
149 - LLaddChar( "." );
150 - }
151 - }
152 -
153 - public void add( char pChar ) {
154 - if ( pChar == ' ' ) {
155 - addNBSP();
156 - } else {
157 - LLaddChar( Character.toString( pChar ) );
158 - }
159 - }
160 -
161 - public void add( String pString ) {
162 - if ( pString != null ) {
163 - for ( int i = 0; i < pString.length(); i++ ) {
164 - add( pString.charAt( i ) );
165 - }
166 - }
167 - }
168 -
169 - public void add( String pString, int pToLength ) {
170 - if ( pString != null ) {
171 - for ( int i = 0; i < pString.length(); i++ ) {
172 - add( pString.charAt( i ) );
173 - pToLength--;
174 - }
175 - addNBSP();
176 - while ( --pToLength > 0 ) {
177 - addSP();
178 - }
179 - }
180 - }
181 -
182 - public String toString() {
183 - return mSB.toString();
184 - }
185 - }
186 - }
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.GWT.client.widgets.*;
5 + import org.litesoft.commonfoundation.base.*;
6 + import org.litesoft.commonfoundation.typeutils.gregorian.*;
7 + import org.litesoft.core.simpletypes.temporal.*;
8 + import org.litesoft.ui.support.nonpublic.*;
9 +
10 + import com.google.gwt.user.client.ui.*;
11 +
12 + import java.util.*;
13 +
14 + public class CreditsPanel
15 + extends SizeableSimplePanel {
16 + public CreditsPanel( CreditsData[] pCreditsData ) {
17 + super( false );
18 +
19 + setWidget( new HTML( createHTML( pCreditsData ) ) );
20 + addStyleName( "litesoft-CreditsFixedFont" );
21 + }
22 +
23 + private String createHTML( CreditsData[] pCreditsData ) {
24 + if ( Currently.isNullOrEmpty( pCreditsData ) ) {
25 + return "";
26 + }
27 +
28 + int longestWhoLength = 2;
29 + CalendarYMD earliestStartDate = pCreditsData[0].getStartDate();
30 + CalendarYMD latestEndDate = pCreditsData[0].getEndDate();
31 + for ( int i = 0; i < pCreditsData.length; i++ ) {
32 + CreditsData creditsData = pCreditsData[i];
33 + int whoLength = creditsData.getWho().length();
34 + CalendarYMD startDate = creditsData.getStartDate();
35 + CalendarYMD endDate = creditsData.getEndDate();
36 + while ( whoLength > longestWhoLength ) {
37 + longestWhoLength += 2;
38 + }
39 + if ( !startDate.afterOrEqual( earliestStartDate ) ) {
40 + earliestStartDate = startDate;
41 + }
42 + if ( !endDate.beforeOrEqual( latestEndDate ) ) {
43 + latestEndDate = endDate;
44 + }
45 + }
46 + longestWhoLength += 3;
47 + Arrays.sort( pCreditsData );
48 + HtmlBuilder builder = new HtmlBuilder( "litesoft-CreditsColorized" );
49 +
50 + // Add Header
51 + for ( int i = longestWhoLength; i > 0; i-- ) {
52 + builder.addNBSP();
53 + }
54 + CreditsData.MonthYear zMY = new CreditsData.MonthYear( earliestStartDate );
55 + do {
56 + builder.addNBSP();
57 + builder.add( zMY.toString() );
58 + }
59 + while ( zMY.incMonth().isLessThanOrEqual( latestEndDate ) );
60 + builder.newLine();
61 +
62 + // Add Seperator
63 + for ( int i = longestWhoLength; i > 0; i-- ) {
64 + builder.add( '-' );
65 + }
66 + zMY = new CreditsData.MonthYear( earliestStartDate );
67 + do {
68 + builder.add( '-' );
69 + builder.add( '+' );
70 + builder.add( '-' );
71 + builder.add( '-' );
72 + builder.add( '-' );
73 + builder.add( '-' );
74 + }
75 + while ( zMY.incMonth().isLessThanOrEqual( latestEndDate ) );
76 + builder.add( '-' );
77 + builder.newLine();
78 +
79 + for ( int i = 0; i < pCreditsData.length; i++ ) {
80 + CreditsData creditsData = pCreditsData[i];
81 + builder.add( creditsData.getWho(), longestWhoLength );
82 + builder.addNBSP();
83 + zMY = new CreditsData.MonthYear( earliestStartDate );
84 + do {
85 + int year = zMY.getYear();
86 + int month = zMY.getMonth();
87 + int daysInMonth = Month.daysIn( year, month );
88 + int lastSplit = (daysInMonth + 18) / 2;
89 + builder.colorize( creditsData.wasActiveDuring( year, month, 1, 6 ) );
90 + builder.add( '|' ); // 1
91 + builder.colorize( creditsData.wasActiveDuring( year, month, 7, 12 ) );
92 + builder.addNBSP(); // 2
93 + builder.colorize( creditsData.wasActiveDuring( year, month, 13, 18 ) );
94 + builder.add( '.' ); // 3
95 + builder.colorize( creditsData.wasActiveDuring( year, month, 19, lastSplit ) );
96 + builder.addNBSP(); // 4
97 + builder.colorize( creditsData.wasActiveDuring( year, month, lastSplit + 1, daysInMonth ) );
98 + builder.add( '.' ); // 5
99 + zMY.incMonth();
100 + builder.colorize( creditsData.wasActiveDuring( zMY.getYear(), zMY.getMonth(), 1, 1 ) );
101 + builder.addNBSP(); // 6
102 + }
103 + while ( zMY.isLessThanOrEqual( latestEndDate ) );
104 + builder.newLine();
105 + }
106 + //To change body of created methods use File | Settings | File Templates.
107 + return builder.toString();
108 + }
109 +
110 + private static class HtmlBuilder {
111 + private StringBuilder mSB = new StringBuilder();
112 + private boolean mColorize = false;
113 + private String mColorStyle;
114 + private int mOffset = 0;
115 +
116 + public HtmlBuilder( String pColorStyle ) {
117 + mColorStyle = pColorStyle;
118 + }
119 +
120 + public void colorize( boolean pColorize ) {
121 + mColorize = pColorize;
122 + }
123 +
124 + public void newLine() {
125 + mColorize = false;
126 + mSB.append( "<br>" );
127 + mOffset = 0;
128 + }
129 +
130 + private void LLaddChar( String pChar ) {
131 + if ( mColorize ) {
132 + mSB.append( "<span class='" ).append( mColorStyle ).append( "'>" );
133 + mSB.append( pChar );
134 + mSB.append( "</span>" );
135 + } else {
136 + mSB.append( pChar );
137 + }
138 + mOffset++;
139 + }
140 +
141 + public void addNBSP() {
142 + LLaddChar( "&nbsp;" );
143 + }
144 +
145 + public void addSP() {
146 + if ( mColorize || ((mOffset & 1) == 1) ) {
147 + addNBSP();
148 + } else {
149 + LLaddChar( "." );
150 + }
151 + }
152 +
153 + public void add( char pChar ) {
154 + if ( pChar == ' ' ) {
155 + addNBSP();
156 + } else {
157 + LLaddChar( Character.toString( pChar ) );
158 + }
159 + }
160 +
161 + public void add( String pString ) {
162 + if ( pString != null ) {
163 + for ( int i = 0; i < pString.length(); i++ ) {
164 + add( pString.charAt( i ) );
165 + }
166 + }
167 + }
168 +
169 + public void add( String pString, int pToLength ) {
170 + if ( pString != null ) {
171 + for ( int i = 0; i < pString.length(); i++ ) {
172 + add( pString.charAt( i ) );
173 + pToLength--;
174 + }
175 + addNBSP();
176 + while ( --pToLength > 0 ) {
177 + addSP();
178 + }
179 + }
180 + }
181 +
182 + public String toString() {
183 + return mSB.toString();
184 + }
185 + }
186 + }