Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.GWT.client.widgets.nonpublic;

import java.util.*;

import org.litesoft.GWT.client.widgets.*;
import org.litesoft.core.simpletypes.temporal.*;
import org.litesoft.core.typeutils.*;
import org.litesoft.core.typeutils.gregorian.*;
import org.litesoft.ui.support.nonpublic.*;

import com.google.gwt.user.client.ui.*;

public class CreditsPanel
        extends SizeableSimplePanel
{
    public CreditsPanel( CreditsData[] pCreditsData )
    {
        super( false );

        setWidget( new HTML( createHTML( pCreditsData ) ) );
        addStyleName( "litesoft-CreditsFixedFont" );
    }

    private String createHTML( CreditsData[] pCreditsData )
    {
        if ( Objects.isNullOrEmpty( pCreditsData ) )
        {
            return "";
        }

        int longestWhoLength = 2;
        CalendarYMD earliestStartDate = pCreditsData[0].getStartDate();
        CalendarYMD latestEndDate = pCreditsData[0].getEndDate();
        for ( int i = 0; i < pCreditsData.length; i++ )
        {
            CreditsData creditsData = pCreditsData[i];
            int whoLength = creditsData.getWho().length();
            CalendarYMD startDate = creditsData.getStartDate();
            CalendarYMD endDate = creditsData.getEndDate();
            while ( whoLength > longestWhoLength )
            {
                longestWhoLength += 2;
            }
            if ( !startDate.afterOrEqual( earliestStartDate ) )
            {
                earliestStartDate = startDate;
            }
            if ( !endDate.beforeOrEqual( latestEndDate ) )
            {
                latestEndDate = endDate;
            }
        }
        longestWhoLength += 3;
        Arrays.sort( pCreditsData );
        HtmlBuilder builder = new HtmlBuilder( "litesoft-CreditsColorized" );

        // Add Header
        for ( int i = longestWhoLength; i > 0; i-- )
        {
            builder.addNBSP();
        }
        CreditsData.MonthYear zMY = new CreditsData.MonthYear( earliestStartDate );
        do
        {
            builder.addNBSP();
            builder.add( zMY.toString() );
        }
        while ( zMY.incMonth().isLessThanOrEqual( latestEndDate ) );
        builder.newLine();

        // Add Seperator
        for ( int i = longestWhoLength; i > 0; i-- )
        {
            builder.add( '-' );
        }
        zMY = new CreditsData.MonthYear( earliestStartDate );
        do
        {
            builder.add( '-' );
            builder.add( '+' );
            builder.add( '-' );
            builder.add( '-' );
            builder.add( '-' );
            builder.add( '-' );
        }
        while ( zMY.incMonth().isLessThanOrEqual( latestEndDate ) );
        builder.add( '-' );
        builder.newLine();

        for ( int i = 0; i < pCreditsData.length; i++ )
        {
            CreditsData creditsData = pCreditsData[i];
            builder.add( creditsData.getWho(), longestWhoLength );
            builder.addNBSP();
            zMY = new CreditsData.MonthYear( earliestStartDate );
            do
            {
                int year = zMY.getYear();
                int month = zMY.getMonth();
                int daysInMonth = Month.daysIn( year, month );
                int lastSplit = (daysInMonth + 18) / 2;
                builder.colorize( creditsData.wasActiveDuring( year, month, 1, 6 ) );
                builder.add( '|' ); //  1
                builder.colorize( creditsData.wasActiveDuring( year, month, 7, 12 ) );
                builder.addNBSP(); //   2
                builder.colorize( creditsData.wasActiveDuring( year, month, 13, 18 ) );
                builder.add( '.' ); //  3
                builder.colorize( creditsData.wasActiveDuring( year, month, 19, lastSplit ) );
                builder.addNBSP(); //   4
                builder.colorize( creditsData.wasActiveDuring( year, month, lastSplit + 1, daysInMonth ) );
                builder.add( '.' ); //  5
                zMY.incMonth();
                builder.colorize( creditsData.wasActiveDuring( zMY.getYear(), zMY.getMonth(), 1, 1 ) );
                builder.addNBSP(); //   6
            }
            while ( zMY.isLessThanOrEqual( latestEndDate ) );
            builder.newLine();
        }
        //To change body of created methods use File | Settings | File Templates.
        return builder.toString();
    }

    private static class HtmlBuilder
    {
        private StringBuilder mSB = new StringBuilder();
        private boolean mColorize = false;
        private String mColorStyle;
        private int mOffset = 0;

        public HtmlBuilder( String pColorStyle )
        {
            mColorStyle = pColorStyle;
        }

        public void colorize( boolean pColorize )
        {
            mColorize = pColorize;
        }

        public void newLine()
        {
            mColorize = false;
            mSB.append( "<br>" );
            mOffset = 0;
        }

        private void LLaddChar( String pChar )
        {
            if ( mColorize )
            {
                mSB.append( "<span class='" ).append( mColorStyle ).append( "'>" );
                mSB.append( pChar );
                mSB.append( "</span>" );
            }
            else
            {
                mSB.append( pChar );
            }
            mOffset++;
        }

        public void addNBSP()
        {
            LLaddChar( "&nbsp;" );
        }

        public void addSP()
        {
            if ( mColorize || ((mOffset & 1) == 1) )
            {
                addNBSP();
            }
            else
            {
                LLaddChar( "." );
            }
        }

        public void add( char pChar )
        {
            if ( pChar == ' ' )
            {
                addNBSP();
            }
            else
            {
                LLaddChar( Character.toString( pChar ) );
            }
        }

        public void add( String pString )
        {
            if ( pString != null )
            {
                for ( int i = 0; i < pString.length(); i++ )
                {
                    add( pString.charAt( i ) );
                }
            }
        }

        public void add( String pString, int pToLength )
        {
            if ( pString != null )
            {
                for ( int i = 0; i < pString.length(); i++ )
                {
                    add( pString.charAt( i ) );
                    pToLength--;
                }
                addNBSP();
                while ( --pToLength > 0 )
                {
                    addSP();
                }
            }
        }

        public String toString()
        {
            return mSB.toString();
        }
    }
}

Commits for litesoft/trunk/Java/GWT/OldClient/src/org/litesoft/GWT/client/widgets/nonpublic/CreditsPanel.java

Diff revisions: vs.
Revision Author Commited Message
863 Diff Diff GeorgeS picture GeorgeS Fri 16 Nov, 2012 22:14:29 +0000
860 Diff Diff GeorgeS picture GeorgeS Mon 05 Nov, 2012 01:39:02 +0000
851 Diff Diff GeorgeS picture GeorgeS Mon 08 Oct, 2012 00:05:32 +0000

Breaking the code as Temporal changes are implemented...

809 Diff Diff GeorgeS picture GeorgeS Thu 16 Aug, 2012 04:10:46 +0000
60 Diff Diff GeorgeS picture GeorgeS Tue 24 Aug, 2010 00:37:36 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000