|
@@ -1,54 +1,54 @@ |
1 |
|
- |
/* |
2 |
|
- |
* Copyright 2008 Google Inc. |
3 |
|
- |
* |
4 |
|
- |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 |
|
- |
* use this file except in compliance with the License. You may obtain a copy of |
6 |
|
- |
* the License at |
7 |
|
- |
* |
8 |
|
- |
* http://www.apache.org/licenses/LICENSE-2.0 |
9 |
|
- |
* |
10 |
|
- |
* Unless required by applicable law or agreed to in writing, software |
11 |
|
- |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 |
|
- |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 |
|
- |
* License for the specific language governing permissions and limitations under |
14 |
|
- |
* the License. |
15 |
|
- |
*/ |
16 |
|
- |
package com.google.gwt.gen2.table.client; |
17 |
|
- |
|
18 |
|
- |
import com.google.gwt.gen2.table.client.TableDefinition.*; |
19 |
|
- |
|
20 |
|
- |
/** |
21 |
|
- |
* The default {@link RowRenderer} used by the {@link DefaultTableDefinition} |
22 |
|
- |
* when the user does not specify one. |
23 |
|
- |
* |
24 |
|
- |
* @param <RowType> the type of the row value |
25 |
|
- |
*/ |
26 |
|
- |
public class DefaultRowRenderer<RowType> implements RowRenderer<RowType> { |
27 |
|
- |
/** |
28 |
|
- |
* The alternating colors to apply to the rows. |
29 |
|
- |
*/ |
30 |
|
- |
private String[] rowColors; |
31 |
|
- |
|
32 |
|
- |
/** |
33 |
|
- |
* Construct a new {@link DefaultRowRenderer}. |
34 |
|
- |
*/ |
35 |
|
- |
public DefaultRowRenderer() { |
36 |
|
- |
this( null ); |
37 |
|
- |
} |
38 |
|
- |
|
39 |
|
- |
/** |
40 |
|
- |
* Construct a new {@link DefaultRowRenderer}. |
41 |
|
- |
* |
42 |
|
- |
* @param rowColors an array of alternating colors to apply to the rows |
43 |
|
- |
*/ |
44 |
|
- |
public DefaultRowRenderer( String[] rowColors ) { |
45 |
|
- |
this.rowColors = rowColors; |
46 |
|
- |
} |
47 |
|
- |
|
48 |
|
- |
public void renderRowValue( RowType rowValue, AbstractRowView<RowType> view ) { |
49 |
|
- |
if ( rowColors != null ) { |
50 |
|
- |
int index = view.getRowIndex() % rowColors.length; |
51 |
|
- |
view.setStyleAttribute( "background", rowColors[index] ); |
52 |
|
- |
} |
53 |
|
- |
} |
54 |
|
- |
} |
|
1 |
+ |
/* |
|
2 |
+ |
* Copyright 2008 Google Inc. |
|
3 |
+ |
* |
|
4 |
+ |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
|
5 |
+ |
* use this file except in compliance with the License. You may obtain a copy of |
|
6 |
+ |
* the License at |
|
7 |
+ |
* |
|
8 |
+ |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
+ |
* |
|
10 |
+ |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
+ |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
12 |
+ |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
13 |
+ |
* License for the specific language governing permissions and limitations under |
|
14 |
+ |
* the License. |
|
15 |
+ |
*/ |
|
16 |
+ |
package com.google.gwt.gen2.table.client; |
|
17 |
+ |
|
|
18 |
+ |
import com.google.gwt.gen2.table.client.TableDefinition.*; |
|
19 |
+ |
|
|
20 |
+ |
/** |
|
21 |
+ |
* The default {@link RowRenderer} used by the {@link DefaultTableDefinition} |
|
22 |
+ |
* when the user does not specify one. |
|
23 |
+ |
* |
|
24 |
+ |
* @param <RowType> the type of the row value |
|
25 |
+ |
*/ |
|
26 |
+ |
public class DefaultRowRenderer<RowType> implements RowRenderer<RowType> { |
|
27 |
+ |
/** |
|
28 |
+ |
* The alternating colors to apply to the rows. |
|
29 |
+ |
*/ |
|
30 |
+ |
private String[] rowColors; |
|
31 |
+ |
|
|
32 |
+ |
/** |
|
33 |
+ |
* Construct a new {@link DefaultRowRenderer}. |
|
34 |
+ |
*/ |
|
35 |
+ |
public DefaultRowRenderer() { |
|
36 |
+ |
this( null ); |
|
37 |
+ |
} |
|
38 |
+ |
|
|
39 |
+ |
/** |
|
40 |
+ |
* Construct a new {@link DefaultRowRenderer}. |
|
41 |
+ |
* |
|
42 |
+ |
* @param rowColors an array of alternating colors to apply to the rows |
|
43 |
+ |
*/ |
|
44 |
+ |
public DefaultRowRenderer( String[] rowColors ) { |
|
45 |
+ |
this.rowColors = rowColors; |
|
46 |
+ |
} |
|
47 |
+ |
|
|
48 |
+ |
public void renderRowValue( RowType rowValue, AbstractRowView<RowType> view ) { |
|
49 |
+ |
if ( rowColors != null ) { |
|
50 |
+ |
int index = view.getRowIndex() % rowColors.length; |
|
51 |
+ |
view.setStyleAttribute( "background", rowColors[index] ); |
|
52 |
+ |
} |
|
53 |
+ |
} |
|
54 |
+ |
} |