Revision 8966

View differences:

org.gvsig.report/tags/org.gvsig.report-1.0.165/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.report.lib.impl.ReportImplLibrary
org.gvsig.report/tags/org.gvsig.report-1.0.165/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/JRFeatureStoreDataSource1.java
1
package org.gvsig.report.lib.impl;
2

  
3
import ar.com.fdvs.dj.domain.CustomExpression;
4
import java.util.HashMap;
5
import java.util.Map;
6
import java.util.Objects;
7
import net.sf.jasperreports.engine.JREmptyDataSource;
8
import net.sf.jasperreports.engine.JRException;
9
import net.sf.jasperreports.engine.JRField;
10
import net.sf.jasperreports.engine.JRRewindableDataSource;
11
import net.sf.jasperreports.engine.JasperReportsContext;
12
import static net.sf.jasperreports.engine.data.JRTableModelDataSource.EXCEPTION_MESSAGE_KEY_UNKNOWN_COLUMN_NAME;
13
import net.sf.jasperreports.engine.data.JsonData;
14
import org.apache.commons.lang3.StringUtils;
15
import org.gvsig.expressionevaluator.Expression;
16
import org.gvsig.expressionevaluator.ExpressionUtils;
17
import org.gvsig.fmap.dal.DALLocator;
18
import org.gvsig.fmap.dal.StoresRepository;
19
import org.gvsig.fmap.dal.feature.Feature;
20
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
21
import org.gvsig.fmap.dal.feature.FeatureStore;
22
import org.gvsig.fmap.dal.feature.FeatureType;
23
import org.gvsig.fmap.dal.feature.LabelsCacheForFieldValues;
24
import static org.gvsig.report.lib.impl.ReportImplLibrary.TAG_REPORT_ATTR_LABEL;
25
import org.gvsig.tools.ToolsLocator;
26
import org.gvsig.tools.dataTypes.CoercionException;
27
import org.gvsig.tools.dataTypes.DataType;
28
import org.gvsig.tools.dataTypes.DataTypesManager;
29
import org.gvsig.tools.dataTypes.Coercion;
30
import org.gvsig.tools.dataTypes.CoercionContext;
31
import org.gvsig.tools.util.GetItem;
32
import org.gvsig.tools.util.GetItem64;
33
import org.gvsig.tools.util.Size;
34
import org.gvsig.tools.util.Size64;
35
import org.gvsig.tools.util.UnmodifiableBasicList64;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

  
39
/**
40
 *
41
 * @author jjdelcerro
42
 */
43
@SuppressWarnings("UseSpecificCatch")
44
public class JRFeatureStoreDataSource1
45
        implements JRRewindableDataSource, JsonData, Size64, Size, GetItem<Feature>, GetItem64<Feature> {
46

  
47
    protected static final Logger LOGGER = LoggerFactory.getLogger(JRFeatureStoreDataSource1.class);
48

  
49
    private UnmodifiableBasicList64<Feature> features;
50
    private long index;
51
    private final StoresRepository storesRepository;
52
    private final JasperReportsContext context;
53
    protected String name;
54
    private Map<String, Coercion> coercions;
55
    private final FeatureType featureType;
56
    private final LabelsCacheForFieldValues labelsCacheForFieldValues;
57

  
58
    public JRFeatureStoreDataSource1(JasperReportsContext context, UnmodifiableBasicList64<Feature> features, StoresRepository storesRepository, FeatureType featureType) {
59
        this.context = context;
60
        this.features = features;
61
        this.storesRepository = storesRepository;
62
        this.index = -1;
63
        this.name = "<unknown>";
64
        this.coercions = new HashMap<>();
65
        this.featureType = featureType;
66
        this.labelsCacheForFieldValues = DALLocator.getDataManager()
67
                .createLabelsCacheForFieldValues((Object... args) -> {
68
                    // FeatureType, Feature, String(fieldName)
69
                    FeatureAttributeDescriptor attr = ((FeatureType)args[0]).getAttributeDescriptor((String)args[2]);
70
                    String labelFormula = attr.getTags().getString(TAG_REPORT_ATTR_LABEL, null);
71
                    return labelFormula;
72
        },null);
73
        LOGGER.info("DataSource(" + this.name + ")");
74
    }
75

  
76
    public JRFeatureStoreDataSource1(JasperReportsContext context, FeatureStore store, Expression filter) {
77
        this(
78
                context,
79
                (UnmodifiableBasicList64<Feature>) store.getFeatures(filter),
80
                store.getStoresRepository(),
81
                store.getDefaultFeatureTypeQuietly()
82
        );
83
        this.name = store.getName();
84
    }
85
    
86
    
87
    @Override
88
    public boolean next() throws JRException {
89
        this.index++;
90
        boolean n = this.index < this.features.size64();
91
        return n;
92
    }
93
    
94
    public String getLabel(Feature feature, String fieldName) {
95
        return this.labelsCacheForFieldValues.getLabelForFieldValue(feature, fieldName);
96
    }
97

  
98
    @Override
99
    public Object getFieldValue(JRField jrField) throws JRException {
100
        String fieldName = jrField.getName();
101
//        System.out.println("DataSurce("+this.name+") ["+this.index+"] getFieldValue("+fieldName+").");
102
        try {
103
            Feature feature = this.features.get64(index);
104
            Object value;
105
            if (fieldName.startsWith("COLUMN_")) {
106
                value = feature.get(Integer.parseInt(fieldName.substring(7)));
107
            } else if (fieldName.endsWith("@label")) {
108
                fieldName = StringUtils.removeEnd(fieldName, "@label");
109
                value = this.getLabel(feature, fieldName);
110
            } else {
111
                value = feature.get(fieldName);
112
            }
113
            if (jrField.getValueClass() != null && !jrField.getValueClass().isInstance(value)) {
114
                Coercion coercion = this.coercions.get(fieldName);
115
                if (coercion == null) {
116
                    DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager();
117
                    DataType dataType = dataTypesManager.getDataType(jrField.getValueClass());
118
                    if (dataType == null) {
119
                        coercion = new DummyCoercion();
120
                    } else {
121
                        coercion = dataType.getCoercion();
122
                    }
123
                    this.coercions.put(fieldName, coercion);
124
                }
125
                try {
126
                    value = coercion.coerce(value);
127
                } catch (CoercionException ex) {
128
                }
129
            }
130
            return value;
131
        } catch (Exception ex) {
132
            if (CustomExpression.class.isAssignableFrom(jrField.getValueClass())) {
133
                return null;
134
            }
135
            throw new JRException(
136
                    EXCEPTION_MESSAGE_KEY_UNKNOWN_COLUMN_NAME,
137
                    new Object[]{fieldName},
138
                    ex
139
            );
140
        }
141
    }
142

  
143
    @Override
144
    public void moveFirst() throws JRException {
145
        this.index = -1;
146
//        System.out.println("DataSurce("+this.name+") ["+this.index+"] moveFirst().");
147
    }
148

  
149
    @Override
150
    public long size64() {
151
        return this.features.size64();
152
    }
153

  
154
    @Override
155
    public int size() {
156
        long sz = this.features.size64();
157
        if (sz > Integer.MAX_VALUE) {
158
            return Integer.MAX_VALUE;
159
        }
160
        return (int) sz;
161
    }
162

  
163
    @Override
164
    public Feature get(int position) {
165
        return this.features.get64(position);
166
    }
167

  
168
    @Override
169
    public Feature get64(long position) {
170
        return this.features.get64(position);
171
    }
172

  
173
    @Override
174
    public JsonData subDataSource() throws JRException {
175
        return new JRFeatureStoreDataSource1(this.context, this.features, this.storesRepository, this.featureType);
176
    }
177

  
178
    @Override
179
    public JsonData subDataSource(String selectExpression) throws JRException {
180
        LOGGER.info("DataSurce(" + this.name + ").subDataSource(" + Objects.toString(selectExpression, "null") + ").");
181
        if (StringUtils.isBlank(selectExpression)) {
182
            return new JREmptyJSonData(1, this.storesRepository);
183
        }
184
        String storeName;
185
        Expression filter = null;
186

  
187
        selectExpression = selectExpression.trim();
188
        if (selectExpression.toUpperCase().startsWith("SELECT ")) {
189
            selectExpression = selectExpression.substring(7).trim();
190
            if (selectExpression.startsWith("* ")) {
191
                selectExpression = selectExpression.substring(2).trim();
192
            }
193
            if (selectExpression.toUpperCase().startsWith("FROM ")) {
194
                selectExpression = selectExpression.substring(5).trim();
195
            }
196
        }
197
        int n = selectExpression.indexOf(" WHERE ");
198
        if (n < 0) {
199
            storeName = selectExpression.trim();
200
        } else {
201
            storeName = selectExpression.substring(0, n).trim();
202
            filter = ExpressionUtils.createExpression(selectExpression.substring(n + 6).trim());
203
        }
204
        if (this.storesRepository.get(storeName) == null) {
205
            return new JREmptyJSonData(1, this.storesRepository);
206
        }
207
        JRFeatureStoreDataSource1 x = new JRFeatureStoreDataSource1(
208
                this.context,
209
                (FeatureStore) this.storesRepository.getStore(storeName),
210
                filter
211
        );
212
        return x;
213
    }
214

  
215
    private class JREmptyJSonData extends JREmptyDataSource implements JsonData {
216

  
217
        JREmptyJSonData(int rows, StoresRepository storesRepository) {
218
            super(rows);
219
        }
220

  
221
        @Override
222
        public JsonData subDataSource() throws JRException {
223
            return JRFeatureStoreDataSource1.this.subDataSource();
224
        }
225

  
226
        @Override
227
        public JsonData subDataSource(String selectExpression) throws JRException {
228
            LOGGER.info("DataSurce(<Empty>) subDataSource(" + Objects.toString(selectExpression, "null") + ")");
229
            return JRFeatureStoreDataSource1.this.subDataSource(selectExpression);
230
        }
231
    }
232

  
233
    private static class DummyCoercion implements Coercion {
234

  
235
        @Override
236
        public Object coerce(Object o) throws CoercionException {
237
            return o;
238
        }
239

  
240
        @Override
241
        public Object coerce(Object value, CoercionContext context) throws CoercionException {
242
            return value;
243
        }
244

  
245
    }
246
}
org.gvsig.report/tags/org.gvsig.report-1.0.165/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/reportbuilder/DefaultStyleBuilder.java
1
package org.gvsig.report.lib.impl.reportbuilder;
2

  
3
import ar.com.fdvs.dj.domain.Style;
4
import ar.com.fdvs.dj.domain.constants.Font;
5
import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
6
import ar.com.fdvs.dj.domain.constants.Rotation;
7
import ar.com.fdvs.dj.domain.constants.Stretching;
8
import ar.com.fdvs.dj.domain.constants.Transparency;
9
import ar.com.fdvs.dj.domain.constants.VerticalAlign;
10
import java.awt.Color;
11
import org.gvsig.report.lib.api.ReportBuilder;
12
import org.gvsig.report.lib.api.ReportBuilder.StyleBuilder;
13
import org.gvsig.tools.persistence.PersistentState;
14
import org.gvsig.tools.persistence.exception.PersistenceException;
15

  
16
/**
17
 *
18
 * @author jjdelcerro
19
 */
20
public class DefaultStyleBuilder implements ReportBuilder.StyleBuilder {
21

  
22
    private Color textColor;
23
    private Color backgroundColor;
24
    private int rotation;
25
    private int stretching;
26
    private boolean stretchingWithOverflow;
27
    private boolean transparent;
28
    private int verticalAlign;
29
    private int horizontalAlign;
30
    private ReportBuilder.BorderBuilder borderTop;
31
    private ReportBuilder.BorderBuilder borderBottom;
32
    private ReportBuilder.BorderBuilder borderLeft;
33
    private ReportBuilder.BorderBuilder borderRight;
34
    private int paddingTop;
35
    private int paddingBottom;
36
    private int paddingLeft;
37
    private int paddingRight;
38
    private int font;
39
    private int fontSize;
40
    private int transparency;
41

  
42
    public DefaultStyleBuilder() {
43
        this.borderTop = new DefaultBorderBuilder();
44
        this.borderBottom = new DefaultBorderBuilder();
45
        this.borderLeft = new DefaultBorderBuilder();
46
        this.borderRight = new DefaultBorderBuilder();
47
        this.textColor = Color.BLACK;
48
        this.backgroundColor = Color.WHITE;
49
        this.transparency = StyleBuilder.TRANSPARENCY_OPAQUE;
50
        this.transparent = false;
51
        this.font = StyleBuilder.FONT_ARIAL;
52
        this.fontSize = 10;
53
        this.paddingBottom = 2;
54
        this.paddingLeft = 2;
55
        this.paddingRight = 2;
56
        this.paddingTop = 2;
57
        this.stretching = StyleBuilder.STRETCHING_RELATIVE_TO_TALLEST_OBJECT;
58
        this.stretchingWithOverflow = true;
59
    }
60

  
61
    @Override
62
    public ReportBuilder.StyleBuilder clone() throws CloneNotSupportedException {
63
        DefaultStyleBuilder other = (DefaultStyleBuilder) super.clone();
64
        other.borderTop = this.borderTop.clone();
65
        other.borderBottom = this.borderBottom.clone();
66
        other.borderLeft = this.borderLeft.clone();
67
        other.borderRight = this.borderRight.clone();
68
        return other;
69
    }
70

  
71
    @Override
72
    public void copyFrom(ReportBuilder.StyleBuilder other) {
73
        try {
74
            this.font = other.getFont();
75
            this.fontSize = other.getFontSize();
76
            this.textColor = other.getTextColor();
77
            this.backgroundColor = other.getBackgroundColor();
78
            this.rotation = other.getRotation();
79
            this.stretching = other.getStretching();
80
            this.stretchingWithOverflow = other.getStretchingWithOverflow();
81
            this.transparency = other.getTransparency();
82
            this.transparent = other.getTransparent();
83
            this.verticalAlign = other.getVerticalAlign();
84
            this.horizontalAlign = other.getHorizontalAlign();
85
            this.paddingTop = other.getPaddingTop();
86
            this.paddingBottom = other.getPaddingBottom();
87
            this.paddingLeft = other.getPaddingLeft();
88
            this.paddingRight = other.getPaddingRight();
89

  
90
            this.borderTop = other.getBorderTop().clone();
91
            this.borderBottom = other.getBorderBottom().clone();
92
            this.borderLeft = other.getBorderLeft().clone();
93
            this.borderRight = other.getBorderRight().clone();
94
        } catch (CloneNotSupportedException ex) {
95
            throw new RuntimeException("Can't copy Style", ex);
96
        }
97
    }
98

  
99
    @Override
100
    public Color getTextColor() {
101
        return this.textColor;
102
    }
103

  
104
    @Override
105
    public ReportBuilder.StyleBuilder textColor(Color textColor) {
106
        this.textColor = textColor;
107
        return this;
108
    }
109

  
110
    @Override
111
    public Color getBackgroundColor() {
112
        return this.backgroundColor;
113
    }
114

  
115
    @Override
116
    public ReportBuilder.StyleBuilder backgroundColor(Color backgroundColor) {
117
        this.backgroundColor = backgroundColor;
118
        return this;
119
    }
120

  
121
    @Override
122
    public int getRotation() {
123
        return this.rotation;
124
    }
125

  
126
    @Override
127
    public ReportBuilder.StyleBuilder rotation(int rotation) {
128
        this.rotation = rotation;
129
        return this;
130
    }
131

  
132
    @Override
133
    public int getStretching() {
134
        return this.stretching;
135
    }
136

  
137
    @Override
138
    public ReportBuilder.StyleBuilder stretching(int stretching) {
139
        this.stretching = stretching;
140
        return this;
141
    }
142

  
143
    @Override
144
    public boolean getStretchingWithOverflow() {
145
        return this.stretchingWithOverflow;
146
    }
147

  
148
    @Override
149
    public ReportBuilder.StyleBuilder stretchingWithOverflow(boolean stretchingWithOverflow) {
150
        this.stretchingWithOverflow = stretchingWithOverflow;
151
        return this;
152
    }
153

  
154
    @Override
155
    public boolean getTransparent() {
156
        return this.transparent;
157
    }
158

  
159
    @Override
160
    public ReportBuilder.StyleBuilder transparent(boolean transparent) {
161
        this.transparent = transparent;
162
        return this;
163
    }
164

  
165
    @Override
166
    public int getTransparency() {
167
        return this.transparency;
168
    }
169

  
170
    @Override
171
    public ReportBuilder.StyleBuilder transparency(int transparency) {
172
        this.transparency = transparency;
173
        return this;
174
    }
175

  
176
    @Override
177
    public int getVerticalAlign() {
178
        return this.verticalAlign;
179
    }
180

  
181
    @Override
182
    public ReportBuilder.StyleBuilder verticalAlign(int verticalAlign) {
183
        this.verticalAlign = verticalAlign;
184
        return this;
185
    }
186

  
187
    @Override
188
    public int getHorizontalAlign() {
189
        return this.horizontalAlign;
190
    }
191

  
192
    @Override
193
    public ReportBuilder.StyleBuilder horizontalAlign(int horizontalAlign) {
194
        this.horizontalAlign = horizontalAlign;
195
        return this;
196
    }
197

  
198
    @Override
199
    public ReportBuilder.BorderBuilder getBorderTop() {
200
        return this.borderTop;
201
    }
202

  
203
    @Override
204
    public ReportBuilder.StyleBuilder borderTop(ReportBuilder.BorderBuilder border) {
205
        this.borderTop = border;
206
        return this;
207
    }
208

  
209
    @Override
210
    public ReportBuilder.BorderBuilder getBorderBottom() {
211
        return this.borderBottom;
212
    }
213

  
214
    @Override
215
    public ReportBuilder.StyleBuilder borderBottom(ReportBuilder.BorderBuilder border) {
216
        this.borderBottom = border;
217
        return this;
218
    }
219

  
220
    @Override
221
    public ReportBuilder.BorderBuilder getBorderLeft() {
222
        return this.borderLeft;
223
    }
224

  
225
    @Override
226
    public ReportBuilder.StyleBuilder borderLeft(ReportBuilder.BorderBuilder border) {
227
        this.borderLeft = border;
228
        return this;
229
    }
230

  
231
    @Override
232
    public ReportBuilder.BorderBuilder getBorderRight() {
233
        return this.borderRight;
234
    }
235

  
236
    @Override
237
    public ReportBuilder.StyleBuilder borderRight(ReportBuilder.BorderBuilder border) {
238
        this.borderRight = border;
239
        return this;
240
    }
241

  
242
    @Override
243
    public int getPaddingTop() {
244
        return this.paddingTop;
245
    }
246

  
247
    @Override
248
    public ReportBuilder.StyleBuilder paddingTop(int padding) {
249
        this.paddingTop = padding;
250
        return this;
251
    }
252

  
253
    @Override
254
    public int getPaddingBottom() {
255
        return this.paddingBottom;
256
    }
257

  
258
    @Override
259
    public ReportBuilder.StyleBuilder paddingBottom(int padding) {
260
        this.paddingBottom = padding;
261
        return this;
262
    }
263

  
264
    @Override
265
    public int getPaddingLeft() {
266
        return this.paddingLeft;
267
    }
268

  
269
    @Override
270
    public ReportBuilder.StyleBuilder paddingLeft(int padding) {
271
        this.paddingLeft = padding;
272
        return this;
273
    }
274

  
275
    @Override
276
    public int getPaddingRight() {
277
        return this.paddingRight;
278
    }
279

  
280
    @Override
281
    public ReportBuilder.StyleBuilder paddingRight(int padding) {
282
        this.paddingRight = padding;
283
        return this;
284
    }
285

  
286
    @Override
287
    public void saveToState(PersistentState ps) throws PersistenceException {
288
        // TODO
289
    }
290

  
291
    @Override
292
    public void loadFromState(PersistentState ps) throws PersistenceException {
293
        // TODO
294
    }
295

  
296
    public static void registerPersistence() {
297
        // TODO
298
    }
299

  
300
    Style build() {
301
        ar.com.fdvs.dj.domain.builders.StyleBuilder builder = new ar.com.fdvs.dj.domain.builders.StyleBuilder(false);
302

  
303
        builder.setTextColor(textColor);
304
        builder.setBackgroundColor(backgroundColor);
305

  
306
        // Prepare font
307
        Font actualFont = new Font();
308
        switch (this.font) {
309
            case FONT_ARIAL:
310
            default:
311
                actualFont.setFontName(Font._FONT_ARIAL);
312
                break;
313
            case FONT_COMIC_SANS:
314
                actualFont.setFontName(Font._FONT_COMIC_SANS);
315
                break;
316
            case FONT_COURIER_NEW:
317
                actualFont.setFontName(Font._FONT_COURIER_NEW);
318
                break;
319
            case FONT_GEORGIA:
320
                actualFont.setFontName(Font._FONT_GEORGIA);
321
                break;
322
            case FONT_MONOSPACED:
323
                actualFont.setFontName(Font._FONT_MONOSPACED);
324
                break;
325
            case FONT_TIME_NEW_ROMAN:
326
                actualFont.setFontName(Font._FONT_TIMES_NEW_ROMAN);
327
                break;
328
            case FONT_VERDANA:
329
                actualFont.setFontName(Font._FONT_VERDANA);
330
                break;
331
        }
332
        actualFont.setFontSize(this.fontSize);
333
        builder.setFont(actualFont);
334
        //
335

  
336
        switch (this.rotation) {
337
            case ROTATION_NONE:
338
            default:
339
                builder.setRotation(Rotation.NONE);
340
                break;
341
            case ROTATION_LEFT:
342
                builder.setRotation(Rotation.LEFT);
343
                break;
344
            case ROTATION_RIGHT:
345
                builder.setRotation(Rotation.RIGHT);
346
                break;
347
        }
348
        switch (this.stretching) {
349
            case STRETCHING_NO_STRETCH:
350
            default:
351
                builder.setStretching(Stretching.NO_STRETCH);
352
                break;
353
            case STRETCHING_RELATIVE_TO_BAND_HEIGHT:
354
                builder.setStretching(Stretching.RELATIVE_TO_BAND_HEIGHT);
355
                builder.setStretchWithOverflow(this.stretchingWithOverflow);
356
                break;
357
            case STRETCHING_RELATIVE_TO_TALLEST_OBJECT:
358
                builder.setStretching(Stretching.RELATIVE_TO_TALLEST_OBJECT);
359
                builder.setStretchWithOverflow(this.stretchingWithOverflow);
360
                break;
361
        }
362
        switch (this.horizontalAlign) {
363
            case HORIZONTALALIGN_LEFT:
364
            default:
365
                builder.setHorizontalAlign(HorizontalAlign.LEFT);
366
                break;
367
            case HORIZONTALALIGN_CENTER:
368
                builder.setHorizontalAlign(HorizontalAlign.CENTER);
369
                break;
370
            case HORIZONTALALIGN_JUSTIFY:
371
                builder.setHorizontalAlign(HorizontalAlign.JUSTIFY);
372
                break;
373
            case HORIZONTALALIGN_RIGHT:
374
                builder.setHorizontalAlign(HorizontalAlign.RIGHT);
375
                break;
376
        }
377
        switch (this.verticalAlign) {
378
            case VERTICALALIGN_MIDDLE:
379
            default:
380
                builder.setVerticalAlign(VerticalAlign.MIDDLE);
381
                break;
382
            case VERTICALALIGN_BOTTOM:
383
                builder.setVerticalAlign(VerticalAlign.BOTTOM);
384
                break;
385
            case VERTICALALIGN_JUSTIFIED:
386
                builder.setVerticalAlign(VerticalAlign.JUSTIFIED);
387
                break;
388
            case VERTICALALIGN_TOP:
389
                builder.setVerticalAlign(VerticalAlign.TOP);
390
                break;
391
        }
392

  
393
        builder.setPaddingTop(this.paddingTop);
394
        builder.setPaddingBottom(this.paddingBottom);
395
        builder.setPaddingLeft(this.paddingLeft);
396
        builder.setPaddingRight(this.paddingRight);
397
        switch (this.transparency) {
398
            case TRANSPARENCY_OPAQUE:
399
            default:
400
                builder.setTransparency(Transparency.OPAQUE);
401
                break;
402
            case TRANSPARENCY_TRANSPARENT:
403
                builder.setTransparency(Transparency.TRANSPARENT);
404
                break;
405
        }
406
        builder.setTransparent(this.transparent);
407

  
408
        builder.setBorderTop(((DefaultBorderBuilder) this.borderTop).build());
409
        builder.setBorderBottom(((DefaultBorderBuilder) this.borderBottom).build());
410
        builder.setBorderLeft(((DefaultBorderBuilder) this.borderLeft).build());
411
        builder.setBorderRight(((DefaultBorderBuilder) this.borderRight).build());
412

  
413
        return builder.build();
414
    }
415

  
416
    @Override
417
    public int getFont() {
418
        return this.font;
419
    }
420

  
421
    @Override
422
    public ReportBuilder.StyleBuilder font(int font) {
423
        this.font = font;
424
        return this;
425
    }
426

  
427
    @Override
428
    public int getFontSize() {
429
        return this.fontSize;
430
    }
431

  
432
    @Override
433
    public ReportBuilder.StyleBuilder fontSize(int fontSize) {
434
        this.fontSize = fontSize;
435
        return this;
436
    }
437
}
org.gvsig.report/tags/org.gvsig.report-1.0.165/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/reportbuilder/DefaultMargins.java
1
package org.gvsig.report.lib.impl.reportbuilder;
2

  
3
import org.gvsig.report.lib.api.ReportBuilder;
4
import org.gvsig.tools.persistence.PersistentState;
5
import org.gvsig.tools.persistence.exception.PersistenceException;
6

  
7
/**
8
 *
9
 * @author jjdelcerro
10
 */
11
public class DefaultMargins implements ReportBuilder.Margins {
12

  
13
    private int top;
14
    private int bottom;
15
    private int left;
16
    private int right;
17
    
18
    public DefaultMargins() {
19
    }
20

  
21
    @Override
22
    public void copyFrom(ReportBuilder.Margins other) {
23
        this.top = other.getTop();
24
        this.bottom = other.getBottom();
25
        this.left = other.getLeft();
26
        this.right = other.getRight();
27
    }
28
    
29
    @Override
30
    public int getTop() {
31
        return this.top;
32
    }
33

  
34
    @Override
35
    public int getBottom() {
36
        return this.bottom;
37
    }
38

  
39
    @Override
40
    public int getLeft() {
41
        return this.left;
42
    }
43

  
44
    @Override
45
    public int getRight() {
46
        return this.right;
47
    }
48

  
49
    @Override
50
    public ReportBuilder.Margins set(int top, int bottom, int left, int right) {
51
        this.top = top;
52
        this.bottom = bottom;
53
        this.left = left;
54
        this.right = right;
55
        return this;
56
    }
57

  
58
    @Override
59
    public ReportBuilder.Margins top(int top) {
60
        this.top = top;
61
        return this;
62
    }
63

  
64
    @Override
65
    public ReportBuilder.Margins bottom(int bottom) {
66
        this.bottom = bottom;
67
        return this;
68
    }
69

  
70
    @Override
71
    public ReportBuilder.Margins left(int left) {
72
        this.left = left;
73
        return this;
74
    }
75

  
76
    @Override
77
    public ReportBuilder.Margins right(int right) {
78
        this.right = right;
79
        return this;
80
    }
81

  
82
    @Override
83
    public ReportBuilder.Margins clone() throws CloneNotSupportedException {
84
        DefaultMargins other = (DefaultMargins) super.clone();
85
        return other;
86
    }
87

  
88
    @Override
89
    public void saveToState(PersistentState ps) throws PersistenceException {
90
        // TODO
91
    }
92

  
93
    @Override
94
    public void loadFromState(PersistentState ps) throws PersistenceException {
95
        // TODO
96
    }
97
    
98
    public static void registerPersistence() {
99
        // TODO
100
    }
101
}
org.gvsig.report/tags/org.gvsig.report-1.0.165/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/reportbuilder/DefaultReportBuilder.java
1
package org.gvsig.report.lib.impl.reportbuilder;
2

  
3
import ar.com.fdvs.dj.core.DynamicJasperHelper;
4
import ar.com.fdvs.dj.core.layout.ClassicLayoutManager;
5
import ar.com.fdvs.dj.core.layout.ExtendedListLayoutManager;
6
import ar.com.fdvs.dj.core.layout.LayoutManager;
7
import ar.com.fdvs.dj.core.layout.ListLayoutManager;
8
import ar.com.fdvs.dj.domain.AutoText;
9
import ar.com.fdvs.dj.domain.DynamicReport;
10
import ar.com.fdvs.dj.domain.Style;
11
import ar.com.fdvs.dj.domain.builders.DynamicReportBuilder;
12
import ar.com.fdvs.dj.domain.constants.Page;
13
import ar.com.fdvs.dj.domain.constants.Transparency;
14
import ar.com.fdvs.dj.domain.entities.DJGroup;
15
import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
16
import java.awt.Color;
17
import java.util.ArrayList;
18
import java.util.Collections;
19
import java.util.HashMap;
20
import java.util.List;
21
import java.util.Map;
22
import net.sf.jasperreports.engine.JasperReport;
23
import org.apache.commons.lang3.StringUtils;
24
import org.gvsig.report.lib.api.Report;
25
import org.gvsig.report.lib.api.ReportBuilder;
26
import org.gvsig.report.lib.api.ReportConfig;
27
import org.gvsig.report.lib.api.ReportDataSet;
28
import org.gvsig.report.lib.api.ReportLocator;
29
import org.gvsig.report.lib.api.ReportManager;
30
import org.gvsig.report.lib.impl.DefaultReport;
31
import org.gvsig.report.lib.impl.DefaultReportConfig;
32
import org.gvsig.tools.persistence.PersistentState;
33
import org.gvsig.tools.persistence.exception.PersistenceException;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

  
37
/**
38
 *
39
 * @author jjdelcerro
40
 */
41
@SuppressWarnings("UseSpecificCatch")
42
public class DefaultReportBuilder implements ReportBuilder {
43

  
44
    private static final Logger LOG = LoggerFactory.getLogger(DefaultReportBuilder.class);
45

  
46
    private String title;
47
    private String subtitle;
48
    private boolean printBackgroundOnOddRows;
49
    private boolean useFullPageWith;
50
    private int detailHeight;
51
    private int columnsPerPage;
52
    private Margins margins;
53
    private List<ColumnBuilder> columns;
54
    private List<GroupBuilder> groups;
55
    private StyleBuilder titleStyle;
56
    private StyleBuilder subtitleStyle;
57
    private boolean printColumnNames;
58
    private int layout;
59
    private int pageFormat;
60
    private boolean showDetailBand;
61
    private Style oddRowBackgroundStyle;
62

  
63
    public DefaultReportBuilder() { 
64
        this.initValues();
65
    }
66
    
67
    private void initValues() {
68
    
69
        this.columns = new ArrayList<>();
70
        this.groups = new ArrayList<>();
71
        this.titleStyle = null;
72
        this.subtitleStyle = null;
73
        this.layout = LAYOUT_CLASSIC;
74
        this.detailHeight = 15;
75
        this.margins = null;
76
        this.useFullPageWith = true;
77
        this.columnsPerPage = 1;
78
        this.printBackgroundOnOddRows = true;
79
        this.printColumnNames = true;
80
        this.showDetailBand = true;
81
        this.oddRowBackgroundStyle = new ar.com.fdvs.dj.domain.builders.StyleBuilder(false, "defaultOddRowStyle")
82
                .setBackgroundColor(new Color(200, 200, 200, 80))
83
                .setTransparency(Transparency.TRANSPARENT).setTransparent(true)
84
                .build();
85
    }
86
    
87
    @Override
88
    public void clean() {
89
        this.initValues();
90
    }
91

  
92
    @Override
93
    public Margins createMargins() {
94
        return new DefaultMargins();
95
    }
96

  
97
    @Override
98
    public ColumnBuilder createColumn() {
99
        return new DefaultColumnBuilder();
100
    }
101

  
102
    @Override
103
    public StyleBuilder createStyle() {
104
        return new DefaultStyleBuilder();
105
    }
106

  
107
    @Override
108
    public BorderBuilder createBorder() {
109
        return new DefaultBorderBuilder();
110
    }
111

  
112
    @Override
113
    public GroupBuilder createGroup(ColumnBuilder columnBuilder) {
114
        return new DefaultGroupBuilder(columnBuilder);
115
    }
116

  
117
    @Override
118
    public String getTitle() {
119
        return this.title;
120
    }
121

  
122
    @Override
123
    public String getSubtitle() {
124
        return this.subtitle;
125
    }
126

  
127
    @Override
128
    public boolean getPrintBackgroundOnOddRows() {
129
        return this.printBackgroundOnOddRows;
130
    }
131

  
132
    @Override
133
    public boolean getUseFullPageWith() {
134
        return this.useFullPageWith;
135
    }
136

  
137
    @Override
138
    public boolean getShowDetailBand() {
139
        return this.showDetailBand;
140
    }
141

  
142
    @Override
143
    public int getDetailHeight() {
144
        return this.detailHeight;
145
    }
146

  
147
    @Override
148
    public int getColumnsPerPage() {
149
        return this.columnsPerPage;
150
    }
151

  
152
    @Override
153
    public Margins getMargins() {
154
        return this.margins;
155
    }
156

  
157
    @Override
158
    public List<ColumnBuilder> getColumns() {
159
        return this.columns;
160
    }
161
    
162
    @Override
163
    public List<GroupBuilder> getGroups() {
164
        return this.groups;
165
    }
166
    
167
    @Override
168
    public StyleBuilder titleStyle() {
169
        if (this.titleStyle == null) {
170
            this.titleStyle = this.createStyle();
171
            this.titleStyle.fontSize(16);
172
        }
173
        return this.titleStyle;
174
    }
175

  
176
    @Override
177
    public StyleBuilder subtitleStyle() {
178
        if (this.subtitleStyle == null) {
179
            this.subtitleStyle = this.createStyle();
180
            this.subtitleStyle.fontSize(12);
181
        }
182
        return this.subtitleStyle;
183
    }
184

  
185
    @Override
186
    public ReportBuilder title(String title) {
187
        this.title = title;
188
        return this;
189
    }
190

  
191
    @Override
192
    public ReportBuilder subtitle(String subtitle) {
193
        this.subtitle = subtitle;
194
        return this;
195
    }
196

  
197
    @Override
198
    public ReportBuilder printBackgroundOnOddRows(boolean printBackgroundOnOddRows) {
199
        this.printBackgroundOnOddRows = printBackgroundOnOddRows;
200
        return this;
201
    }
202

  
203
    @Override
204
    public ReportBuilder useFullPageWith(boolean useFullPageWith) {
205
        this.useFullPageWith = useFullPageWith;
206
        return this;
207
    }
208

  
209
    @Override
210
    public ReportBuilder showDetailBand(boolean showDetailBand) {
211
        this.showDetailBand = showDetailBand;
212
        return this;
213
    }
214

  
215
    @Override
216
    public ReportBuilder detailHeight(int detailHeight) {
217
        this.detailHeight = detailHeight;
218
        return this;
219
    }
220

  
221
    @Override
222
    public ReportBuilder columnsPerPage(int columnsPerPage) {
223
        this.columnsPerPage = columnsPerPage;
224
        return this;
225
    }
226

  
227
    @Override
228
    public ColumnBuilder add_column() {
229
        ColumnBuilder column = this.createColumn();
230
        this.columns.add(column);
231
        return column;
232
    }
233

  
234
    @Override
235
    public ReportBuilder margins(int top, int bottom, int left, int right) {
236
        if (this.margins == null) {
237
            this.margins = this.createMargins();
238
        }
239
        this.margins.set(top, bottom, left, right);
240
        return this;
241
    }
242

  
243
    @Override
244
    public int getLayout() {
245
        return this.layout;
246
    }
247

  
248
    @Override
249
    public boolean getPrintColumnNames() {
250
        return this.printColumnNames;
251
    }
252

  
253
    @Override
254
    public ReportBuilder printColumnNames(boolean printColumnNames) {
255
        this.printColumnNames = printColumnNames;
256
        return this;
257
    }
258

  
259
    @Override
260
    public int getPageFormat() {
261
        return this.pageFormat;
262
    }
263

  
264
    @Override
265
    public ReportBuilder pageFormat(int pageFormat) {
266
        this.pageFormat = pageFormat;
267
        return this;
268
    }
269

  
270
    @Override
271
    public ReportBuilder layout(int layout) {
272
        this.layout = layout;
273
        return this;
274
    }
275

  
276
    private LayoutManager getLayoutManager() {
277
        switch (this.layout) {
278
            case LAYOUT_LIST:
279
                return new ListLayoutManager();
280
            case LAYOUT_EXTENDEDLIST:
281
                return new ExtendedListLayoutManager();
282
            case LAYOUT_CLASSIC:
283
            default:
284
                return new ClassicLayoutManager();
285
        }
286

  
287
    }
288

  
289
    @Override
290
    public ReportBuilder clone() throws CloneNotSupportedException {
291
        DefaultReportBuilder other = (DefaultReportBuilder) super.clone();
292
        if (this.margins != null) {
293
            other.margins = this.margins.clone();
294
        }
295
        if (this.titleStyle != null) {
296
            other.titleStyle = this.titleStyle.clone();
297
        }
298
        if (this.subtitleStyle != null) {
299
            other.subtitleStyle = this.subtitleStyle.clone();
300
        }
301
        other.columns.retainAll(Collections.EMPTY_LIST);
302
        for (ColumnBuilder column : this.columns) {
303
            other.columns.add(column.clone());
304
        }
305
        return other;
306
    }
307

  
308
    @Override
309
    public void copyFrom(ReportBuilder other) {
310
        try {
311
            this.title = other.getTitle();
312
            this.subtitle = other.getSubtitle();
313
            this.printBackgroundOnOddRows = other.getPrintBackgroundOnOddRows();
314
            this.useFullPageWith = other.getUseFullPageWith();
315
            this.showDetailBand = other.getShowDetailBand();
316
            this.detailHeight = other.getDetailHeight();
317
            this.columnsPerPage = other.getColumnsPerPage();
318
            this.printColumnNames = other.getPrintColumnNames();
319
            this.layout = other.getLayout();
320
            this.pageFormat = other.getPageFormat();
321

  
322
            if (other.getMargins() != null) {
323
                this.margins = other.getMargins().clone();
324
            }
325
            if (other.titleStyle() != null) {
326
                this.titleStyle = other.titleStyle().clone();
327
            }
328
            if (other.subtitleStyle() != null) {
329
                this.subtitleStyle = other.subtitleStyle().clone();
330
            }
331

  
332
            this.columns.retainAll(Collections.EMPTY_LIST);
333
            for (ColumnBuilder column : other.getColumns()) {
334
                this.columns.add(column.clone());
335
            }
336
        } catch (CloneNotSupportedException ex) {
337
            throw new RuntimeException("Can't copy ReportBuilder", ex);
338
        }
339
    }
340

  
341
    public Report toReport(ReportDataSet dataSet) {
342
        DynamicReportBuilder builder = new DynamicReportBuilder();
343
        if (!StringUtils.isBlank(this.title)) {
344
            builder.setTitle(this.title);
345
            if (this.titleStyle != null) {
346
                builder.setTitleStyle(((DefaultStyleBuilder) this.titleStyle).build());
347
            }
348
        }
349
        if (!StringUtils.isBlank(this.subtitle)) {
350
            builder.setSubtitle(this.subtitle);
351
            if (this.subtitleStyle != null) {
352
                builder.setSubtitleStyle(((DefaultStyleBuilder) this.subtitleStyle).build());
353
            }
354
        }
355
        builder.setColumnsPerPage(this.columnsPerPage);
356
        if (this.detailHeight > 0) {
357
            builder.setDetailHeight(this.detailHeight);
358
        }
359
        builder.setUseFullPageWidth(this.useFullPageWith);
360
        builder.setPrintBackgroundOnOddRows(this.printBackgroundOnOddRows);
361
        builder.setOddRowBackgroundStyle(this.oddRowBackgroundStyle);
362
        if (this.margins != null) {
363
            builder.setMargins(
364
                    this.margins.getTop(),
365
                    this.margins.getBottom(),
366
                    this.margins.getLeft(),
367
                    this.margins.getRight()
368
            );
369
        }
370
        builder.setPrintColumnNames(this.printColumnNames);
371

  
372
        switch (this.pageFormat) {
373
            case PAGE_A4_PORTRAIT:
374
            default:
375
                builder.setPageSizeAndOrientation(Page.Page_A4_Portrait());
376
                break;
377
            case PAGE_A4_LANDSCAPE:
378
                builder.setPageSizeAndOrientation(Page.Page_A4_Landscape());
379
                break;
380
            case PAGE_LEGAL_PORTRAIT:
381
                builder.setPageSizeAndOrientation(Page.Page_Legal_Portrait());
382
                break;
383
            case PAGE_LEGAL_LANDSCAPE:
384
                builder.setPageSizeAndOrientation(Page.Page_Legal_Landscape());
385
                break;
386
            case PAGE_LETTER_PORTRAIT:
387
                builder.setPageSizeAndOrientation(Page.Page_Letter_Portrait());
388
                break;
389
            case PAGE_LETTER_LANDSCAPE:
390
                builder.setPageSizeAndOrientation(Page.Page_Letter_Landscape());
391
                break;
392
        }
393

  
394
        // Style column builder
395
        HashMap<String, AbstractColumn> mapColumns = new HashMap<String, AbstractColumn>();
396
        for (ColumnBuilder column : this.columns) {
397
            DefaultColumnBuilder columnBuilder = (DefaultColumnBuilder) column;
398
            AbstractColumn columnState = columnBuilder.build();
399
            mapColumns.put(column.getColumnName(), columnState);
400

  
401
            builder.addColumn(columnState);
402
        }
403

  
404
        // GroupBy builder
405
        for (GroupBuilder group : this.groups) {
406
            DJGroup groupBuilder = ((DefaultGroupBuilder) group).build(mapColumns, this.columns);
407
            builder.addGroup(groupBuilder);
408
        }
409
        builder.setShowDetailBand(this.showDetailBand);
410

  
411
        builder.addAutoText(AutoText.AUTOTEXT_PAGE_X_SLASH_Y, AutoText.POSITION_FOOTER, AutoText.ALIGNMENT_RIGHT);
412

  
413
        Map params = new HashMap();
414
        try {
415
            DynamicReport dynamicReport = builder.build();
416
            JasperReport jasperReport = DynamicJasperHelper.generateJasperReport(
417
                    dynamicReport,
418
                    this.getLayoutManager(),
419
                    params
420
            );
421
            ReportManager reportManager = ReportLocator.getReportManager();
422
            ReportConfig config = new DefaultReportConfig();
423
            config.setDataSet(dataSet);
424
            config.setName(this.title);
425
            config.setLayoutManager(this.layout);
426
            Report report = new DefaultReport(config, dynamicReport);
427
            return report;
428
        } catch (Exception ex) {
429
            LOG.warn("Can't create report.", ex);
430
            return null;
431
        }
432
    }
433

  
434
    @Override
435
    public void saveToState(PersistentState ps) throws PersistenceException {
436
        // TODO: Guardar en el state
437
    }
438

  
439
    @Override
440
    public void loadFromState(PersistentState ps) throws PersistenceException {
441
        // TODO: Cargar desde el state
442
    }
443

  
444
    public static void selfRegister() {
445
        // TODO: Registrar la persistencia
446
    }
447

  
448
    @Override
449
    public GroupBuilder add_group(ColumnBuilder columnBuilder) {
450
        GroupBuilder group = this.createGroup(columnBuilder);
451
        this.groups.add(group);
452
        return group;
453
    }
454
}
org.gvsig.report/tags/org.gvsig.report-1.0.165/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/reportbuilder/DefaultGroupBuilder.java
1
package org.gvsig.report.lib.impl.reportbuilder;
2

  
3
import ar.com.fdvs.dj.domain.DJCalculation;
4
import ar.com.fdvs.dj.domain.Style;
5
import ar.com.fdvs.dj.domain.constants.Font;
6
import ar.com.fdvs.dj.domain.constants.GroupLayout;
7
import ar.com.fdvs.dj.domain.constants.HorizontalAlign;
8
import ar.com.fdvs.dj.domain.constants.VerticalAlign;
9
import ar.com.fdvs.dj.domain.entities.DJGroup;
10
import ar.com.fdvs.dj.domain.entities.columns.AbstractColumn;
11
import ar.com.fdvs.dj.domain.entities.columns.PropertyColumn;
12
import java.util.HashMap;
13
import java.util.List;
14
import org.gvsig.report.lib.api.ReportBuilder;
15
import org.gvsig.report.lib.api.ReportBuilder.ColumnBuilder;
16
import org.gvsig.report.lib.api.ReportBuilder.GroupBuilder;
17
import org.gvsig.tools.persistence.PersistentState;
18
import org.gvsig.tools.persistence.exception.PersistenceException;
19

  
20
/**
21
 *
22
 * @author osc
23
 */
24
public class DefaultGroupBuilder implements ReportBuilder.GroupBuilder {
25

  
26
    private int groupLayout;
27
    private boolean startInNewColumn;
28
    private boolean startInNewPage;
29
    private final ColumnBuilder columnBuilder;
30

  
31
    public DefaultGroupBuilder(ColumnBuilder columnBuilder) {
32
        this.columnBuilder = columnBuilder;
33
        this.startInNewColumn = false;
34
        this.startInNewPage = false;
35
        this.groupLayout = GroupBuilder.GROUP_LAYOUT_VALUE_IN_HEADER;
36
    }
37

  
38
    @Override
39
    public ColumnBuilder getColumnBuilder() {
40
        return this.columnBuilder;
41
    }
42

  
43
    public DJGroup build(HashMap<String, AbstractColumn> mapColumns, List<ColumnBuilder> columnBuilders) {
44
        ar.com.fdvs.dj.domain.builders.GroupBuilder gb1 = new ar.com.fdvs.dj.domain.builders.GroupBuilder();
45
        AbstractColumn abstractColumn = mapColumns.get(this.columnBuilder.getColumnName());
46
        gb1.setCriteriaColumn((PropertyColumn) abstractColumn);
47

  
48
        Style headerVariables = new Style();
49
        headerVariables.setFont(Font.ARIAL_MEDIUM_BOLD);
50
        headerVariables.setHorizontalAlign(HorizontalAlign.RIGHT);
51
        headerVariables.setVerticalAlign(VerticalAlign.MIDDLE);
52

  
53
        for (ColumnBuilder col : columnBuilders) {
54
            if (col.showGroupByField()) {
55
                DJCalculation operation = getDJOperation(col.getGroupByOperation());
56
                AbstractColumn columnValue = mapColumns.get(col.getColumnName());
57
                gb1.addFooterVariable(columnValue, operation, headerVariables);
58
            }
59
        }
60

  
61
        GroupLayout dynamicJasperGroupLayout;
62
        switch (groupLayout) {
63
            case GroupBuilder.GROUP_LAYOUT_DEFAULT:
64
            default:
65
                dynamicJasperGroupLayout = GroupLayout.DEFAULT;
66
                break;
67
            case GroupBuilder.GROUP_LAYOUT_DEFAULT_WITH_HEADER:
68
                dynamicJasperGroupLayout = GroupLayout.DEFAULT_WITH_HEADER;
69
                break;
70
            case GroupBuilder.GROUP_LAYOUT_EMPTY:
71
                dynamicJasperGroupLayout = GroupLayout.EMPTY;
72
                break;
73
            case GroupBuilder.GROUP_LAYOUT_VALUE_FOR_EACH:
74
                dynamicJasperGroupLayout = GroupLayout.VALUE_FOR_EACH;
75
                break;
76
            case GroupBuilder.GROUP_LAYOUT_VALUE_FOR_EACH_WITH_HEADERS:
77
                dynamicJasperGroupLayout = GroupLayout.VALUE_FOR_EACH_WITH_HEADERS;
78
                break;
79
            case GroupBuilder.GROUP_LAYOUT_VALUE_IN_HEADER:
80
                dynamicJasperGroupLayout = GroupLayout.VALUE_IN_HEADER;
81
                break;
82
            case GroupBuilder.GROUP_LAYOUT_VALUE_IN_HEADER_AND_FOR_EACH:
83
                dynamicJasperGroupLayout = GroupLayout.VALUE_IN_HEADER_AND_FOR_EACH;
84
                break;
85
            case GroupBuilder.GROUP_LAYOUT_VALUE_IN_HEADER_AND_FOR_EACH_WITH_HEADERS:
86
                dynamicJasperGroupLayout = GroupLayout.VALUE_IN_HEADER_AND_FOR_EACH_WITH_HEADERS;
87
                break;
88
            case GroupBuilder.GROUP_LAYOUT_VALUE_IN_HEADER_WITH_HEADERS:
89
                dynamicJasperGroupLayout = GroupLayout.VALUE_IN_HEADER_WITH_HEADERS;
90
                break;
91
            case GroupBuilder.GROUP_LAYOUT_VALUE_IN_HEADER_WITH_HEADERS_AND_COLUMN_NAME:
92
                dynamicJasperGroupLayout = GroupLayout.VALUE_IN_HEADER_WITH_HEADERS_AND_COLUMN_NAME;
93
                break;
94

  
95
        }
96
        gb1.setGroupLayout(dynamicJasperGroupLayout);
97

  
98
        return gb1.build();
99
    }
100

  
101
    private DJCalculation getDJOperation(int operation) {
102
        switch (operation) {
103
            case ReportBuilder.GROUPBY_OPERATION_AVERAGE:
104
            default:
105
                return DJCalculation.AVERAGE;
106
            case ReportBuilder.GROUPBY_OPERATION_COUNT:
107
                return DJCalculation.COUNT;
108
            case ReportBuilder.GROUPBY_OPERATION_FIRST:
109
                return DJCalculation.FIRST;
110
            case ReportBuilder.GROUPBY_OPERATION_HIGHEST:
111
                return DJCalculation.HIGHEST;
112
            case ReportBuilder.GROUPBY_OPERATION_LOWEST:
113
                return DJCalculation.LOWEST;
114
            case ReportBuilder.GROUPBY_OPERATION_NOTHING:
115
                return DJCalculation.NOTHING;
116
            case ReportBuilder.GROUPBY_OPERATION_STANDARD_DEVIATION:
117
                return DJCalculation.STANDARD_DEVIATION;
118
            case ReportBuilder.GROUPBY_OPERATION_SUM:
119
                return DJCalculation.SUM;
120
            case ReportBuilder.GROUPBY_OPERATION_SYSTEM:
121
                return DJCalculation.SYSTEM;
122
            case ReportBuilder.GROUPBY_OPERATION_VARIANCE:
123
                return DJCalculation.VARIANCE;
124
        }
125
    }
126

  
127
    @Override
128
    public int getGroupLayout() {
129
        return this.groupLayout;
130
    }
131

  
132
    @Override
133
    public void groupLayout(int groupLayout) {
134
        this.groupLayout = groupLayout;
135
    }
136

  
137
    @Override
138
    public boolean getStartInNewColumn() {
139
        return this.startInNewColumn;
140
    }
141

  
142
    @Override
143
    public void startInNewColumn(boolean startInNewColumn) {
144
        this.startInNewColumn = startInNewColumn;
145
    }
146

  
147
    @Override
148
    public boolean getStartInNewPage() {
149
        return this.startInNewPage;
150
    }
151

  
152
    @Override
153
    public void startInNewPage(boolean startInNewPage) {
154
        this.startInNewPage = startInNewPage;
155
    }
156

  
157
    @Override
158
    public ReportBuilder.GroupBuilder clone() throws CloneNotSupportedException {
159
        DefaultGroupBuilder other = (DefaultGroupBuilder) super.clone();
160
        return other;
161
    }
162

  
163
    @Override
164
    public void copyFrom(ReportBuilder.GroupBuilder other) {
165
        this.groupLayout = other.getGroupLayout();
166
        this.startInNewColumn = other.getStartInNewColumn();
167
        this.startInNewPage = other.getStartInNewPage();
168
    }
169

  
170
    @Override
171
    public void saveToState(PersistentState state) throws PersistenceException {
172
        //todo
173
    }
174

  
175
    @Override
176
    public void loadFromState(PersistentState state) throws PersistenceException {
177
        // todo
178
    }
179
}
org.gvsig.report/tags/org.gvsig.report-1.0.165/org.gvsig.report.lib/org.gvsig.report.lib.impl/src/main/java/org/gvsig/report/lib/impl/reportbuilder/DefaultBorderBuilder.java
1
package org.gvsig.report.lib.impl.reportbuilder;
2

  
3
import ar.com.fdvs.dj.domain.constants.Border;
4
import java.awt.Color;
5
import org.gvsig.report.lib.api.ReportBuilder;
6
import org.gvsig.report.lib.api.ReportBuilder.BorderBuilder;
7
import org.gvsig.tools.persistence.PersistentState;
8
import org.gvsig.tools.persistence.exception.PersistenceException;
9

  
10
/**
11
 *
12
 * @author jjdelcerro
13
 */
14
public class DefaultBorderBuilder implements ReportBuilder.BorderBuilder {
15

  
16
    private Color color;
17
    private int lineStyle;
18
    private int width;
19

  
20
    public DefaultBorderBuilder() {
21
        this.color = Color.BLACK;
22
        this.width = 0;
23
        this.lineStyle = BorderBuilder.WIDTH_1POINT;
24
    }
25

  
26
    @Override
27
    public BorderBuilder clone() throws CloneNotSupportedException {
28
        DefaultBorderBuilder other = (DefaultBorderBuilder) super.clone();
29
        return other;
30
    }
31

  
32
    @Override
33
    public void copyFrom(BorderBuilder other) {
34
        this.color = other.getColor();
35
        this.width = other.getWidth();
36
        this.lineStyle = other.getLineStyle();
37
    }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff