OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 110 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 110 Rev 159
Line 20... Line 20...
20
import org.olap4j.CellSet;
20
import org.olap4j.CellSet;
21
import org.olap4j.CellSetAxis;
21
import org.olap4j.CellSetAxis;
22
import org.olap4j.Position;
22
import org.olap4j.Position;
23
import org.olap4j.impl.CoordinateIterator;
23
import org.olap4j.impl.CoordinateIterator;
24
import org.olap4j.impl.Olap4jUtil;
24
import org.olap4j.impl.Olap4jUtil;
25
 
-
 
26
import org.olap4j.metadata.Member;
25
import org.olap4j.metadata.Member;
27
 
26
 
28
public class CellSetRenderer extends JComponent implements Scrollable {
27
public class CellSetRenderer extends JComponent implements Scrollable {
29
    private static final Color BORDER_COLOR = Color.LIGHT_GRAY;
28
    private static final Color BORDER_COLOR = Color.LIGHT_GRAY;
30
    private CellSet cellSet;
29
    private CellSet cellSet;
Line 32... Line 31...
32
    private AxisInfo columnsAxisInfo;
31
    private AxisInfo columnsAxisInfo;
33
    private CellSetAxis rowsAxis;
32
    private CellSetAxis rowsAxis;
34
    private AxisInfo rowsAxisInfo;
33
    private AxisInfo rowsAxisInfo;
35
    private int w;
34
    private int w;
36
    private int h;
35
    private int h;
-
 
36
    private Matrix matrix;
37
 
37
 
38
    public CellSetRenderer() {
38
    public CellSetRenderer() {
39
 
39
 
40
    }
40
    }
41
 
41
 
-
 
42
    public Matrix getMatrix() {
-
 
43
        return matrix;
-
 
44
    }
-
 
45
 
42
    public CellSetRenderer(CellSet set) {
46
    public CellSetRenderer(CellSet set) {
43
        this.cellSet = set;
47
        this.cellSet = set;
44
        computeCells();
48
        computeCells();
45
    }
49
    }
46
 
50
 
47
    public void setCellSet(CellSet set) {
51
    public void setCellSet(CellSet set) {
48
 
-
 
-
 
52
        this.matrix = null;
49
        this.cellSet = set;
53
        this.cellSet = set;
50
        computeCells();
54
        computeCells();
51
        repaint();
55
        repaint();
52
        this.setSize(new Dimension(w, h));
56
        this.setSize(new Dimension(w, h));
53
    }
57
    }
54
 
58
 
-
 
59
    public void setMatrix(Matrix matrix2) {
-
 
60
        this.matrix = matrix2;
-
 
61
        this.cellSet = null;
-
 
62
        this.rowsAxis = null;
-
 
63
        this.rowsAxisInfo = null;
-
 
64
        this.columnsAxis = null;
-
 
65
        this.columnsAxisInfo = null;
-
 
66
        repaint();
-
 
67
        this.setSize(new Dimension(w, h));
-
 
68
    }
-
 
69
 
55
    private void computeCells() {
70
    private void computeCells() {
56
        if (cellSet == null) {
71
        if (cellSet == null) {
57
            return;
72
            return;
58
        }
73
        }
59
 
74
 
Line 78... Line 93...
78
        rowsAxisInfo = computeAxisInfo(rowsAxis);
93
        rowsAxisInfo = computeAxisInfo(rowsAxis);
79
 
94
 
80
    }
95
    }
81
 
96
 
82
    boolean isOuside(int x, int y) {
97
    boolean isOuside(int x, int y) {
-
 
98
        if (rowsAxisInfo == null) {
-
 
99
            return false;
-
 
100
        }
83
        return x < rowsAxisInfo.getWidth() && y < columnsAxisInfo.getWidth();
101
        return x < rowsAxisInfo.getWidth() && y < columnsAxisInfo.getWidth();
84
    }
102
    }
85
 
103
 
86
    boolean isValue(int x, int y) {
104
    boolean isValue(int x, int y) {
-
 
105
        if (rowsAxisInfo == null) {
-
 
106
            return true;
-
 
107
        }
87
        return x >= rowsAxisInfo.getWidth() && y >= columnsAxisInfo.getWidth();
108
        return x >= rowsAxisInfo.getWidth() && y >= columnsAxisInfo.getWidth();
88
    }
109
    }
89
 
110
 
90
    @Override
111
    @Override
91
    protected void paintComponent(Graphics g) {
112
    protected void paintComponent(Graphics g) {
Line 96... Line 117...
96
            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
117
            g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
97
        }
118
        }
98
 
119
 
99
        g.setColor(Color.WHITE);
120
        g.setColor(Color.WHITE);
100
        g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
121
        g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
-
 
122
 
101
        if (cellSet == null) {
123
        if (cellSet == null && matrix == null) {
102
            return;
124
            return;
103
        }
125
        }
104
 
126
 
105
        if (cellSet.getAxes().size() > 2) {
127
        if (cellSet != null && cellSet.getAxes().size() > 2) {
106
            int[] dimensions = new int[cellSet.getAxes().size() - 2];
128
            int[] dimensions = new int[cellSet.getAxes().size() - 2];
107
            for (int i = 2; i < cellSet.getAxes().size(); i++) {
129
            for (int i = 2; i < cellSet.getAxes().size(); i++) {
108
                CellSetAxis cellSetAxis = cellSet.getAxes().get(i);
130
                CellSetAxis cellSetAxis = cellSet.getAxes().get(i);
109
                dimensions[i - 2] = cellSetAxis.getPositions().size();
131
                dimensions[i - 2] = cellSetAxis.getPositions().size();
110
            }
132
            }
Line 134... Line 156...
134
                System.out.println();
156
                System.out.println();
135
            }
157
            }
136
        }
158
        }
137
        // Figure out the dimensions of the blank rectangle in the top left
159
        // Figure out the dimensions of the blank rectangle in the top left
138
        // corner.
160
        // corner.
139
        final int yOffset = columnsAxisInfo.getWidth();
161
        int yOffset = 0;
140
        final int xOffsset = rowsAxisInfo.getWidth();
162
        int xOffsset = 0;
141
 
163
 
142
        // Populate a string matrix
164
        // Populate a string matrix
-
 
165
        if (matrix == null) {
-
 
166
            yOffset = columnsAxisInfo.getWidth();
-
 
167
            xOffsset = rowsAxisInfo.getWidth();
143
        Matrix matrix = new Matrix(xOffsset + (columnsAxis == null ? 1 : columnsAxis.getPositions().size()), yOffset + (rowsAxis == null ? 1 : rowsAxis.getPositions().size()));
168
            this.matrix = new Matrix(xOffsset + (columnsAxis == null ? 1 : columnsAxis.getPositions().size()), yOffset + (rowsAxis == null ? 1 : rowsAxis.getPositions().size()));
144
 
169
 
145
        // Populate corner
170
            // Populate corner
146
        for (int x = 0; x < xOffsset; x++) {
171
            for (int x = 0; x < xOffsset; x++) {
147
            for (int y = 0; y < yOffset; y++) {
172
                for (int y = 0; y < yOffset; y++) {
148
                matrix.set(x, y, "", false, x > 0);
173
                    matrix.set(x, y, "", false, x > 0);
Line 165... Line 190...
165
            if (coordList.size() > 1) {
190
                if (coordList.size() > 1) {
166
                y += coordList.get(1);
191
                    y += coordList.get(1);
167
            }
192
                }
168
            matrix.set(x, y, cell.getFormattedValue(), true, false);
193
                matrix.set(x, y, cell.getFormattedValue(), true, false);
169
        }
194
            }
170
 
195
        }
171
        final int matrixWidth = matrix.getWidth();
196
        final int matrixWidth = matrix.getWidth();
172
        final int matrixHeight = matrix.getHeight();
197
        final int matrixHeight = matrix.getHeight();
173
        int[] columnWidths = new int[matrixWidth];
198
        int[] columnWidths = new int[matrixWidth];
174
        int widestWidth = 0;
199
        int widestWidth = 0;
175
        int offsetX = 0;
200
        int offsetX = 0;
Line 235... Line 260...
235
                            g.setFont(boldFont);
260
                            g.setFont(boldFont);
236
                        }
261
                        }
237
 
262
 
238
                        g.drawString(value, xString, y * lineHeight + (int) (spaceH * 1.4f));
263
                        g.drawString(value, xString, y * lineHeight + (int) (spaceH * 1.4f));
239
                    }
264
                    }
240
 
-
 
-
 
265
                    if (columnsAxisInfo != null) {
241
                    // Top
266
                        // Top
242
                    if (!isOuside(x, y)
267
                        if (!isOuside(x, y)
243
                            && (value.length() > 0 || y == columnsAxisInfo.getWidth() || isValue(x, y) || (!isValue(x, y) && (leftNotEmpty(matrix, x, y - 1)) || leftNotEmpty(matrix, x, y)))) {
268
                                && (value.length() > 0 || y == columnsAxisInfo.getWidth() || isValue(x, y) || (!isValue(x, y) && (leftNotEmpty(matrix, x, y - 1)) || leftNotEmpty(matrix, x, y)))) {
244
                        g.setColor(BORDER_COLOR);
269
                            g.setColor(BORDER_COLOR);
245
                        g.drawLine(offsetX, y * lineHeight, offsetX + columnWidth, y * lineHeight);
270
                            g.drawLine(offsetX, y * lineHeight, offsetX + columnWidth, y * lineHeight);
246
 
271
 
247
                    }
272
                        }
-
 
273
 
-
 
274
                        if (rowsAxisInfo != null) {
248
                    if ((y < columnsAxisInfo.getWidth() && x >= rowsAxisInfo.getWidth()) || isValue(x, y) || (!isOuside(x, y) && (!leftNotEmpty(matrix, x, y) || !isValue(x, y)))) {
275
                            if ((y < columnsAxisInfo.getWidth() && x >= rowsAxisInfo.getWidth()) || isValue(x, y) || (!isOuside(x, y) && (!leftNotEmpty(matrix, x, y) || !isValue(x, y)))) {
249
                        g.setColor(BORDER_COLOR);
276
                                g.setColor(BORDER_COLOR);
250
                        // Left
277
                                // Left
251
                        g.drawLine(offsetX, y * lineHeight, offsetX, (y + 1) * lineHeight);
278
                                g.drawLine(offsetX, y * lineHeight, offsetX, (y + 1) * lineHeight);
252
                    }
279
                            }
253
 
280
 
254
                }
281
                        }
-
 
282
                    } else {
-
 
283
                        g.setColor(BORDER_COLOR);
-
 
284
                        g.drawLine(offsetX, y * lineHeight, offsetX + columnWidth, y * lineHeight);
-
 
285
                        g.drawLine(offsetX, y * lineHeight, offsetX, (y + 1) * lineHeight);
-
 
286
                    }
-
 
287
                }
-
 
288
 
255
            }
289
            }
256
            offsetX += columnWidth;
290
            offsetX += columnWidth;
257
            widestWidth = Math.max(columnWidth, widestWidth);
291
            widestWidth = Math.max(columnWidth, widestWidth);
258
        }
292
        }
259
        // Right
293
        // Right
260
        g.setColor(BORDER_COLOR);
294
        g.setColor(BORDER_COLOR);
-
 
295
 
261
        final int bottomRightX = offsetX;
296
        final int bottomRightX = offsetX;
262
        final int bottomRightY = matrixHeight * lineHeight;
297
        final int bottomRightY = matrixHeight * lineHeight;
263
        g.drawLine(offsetX, 0, offsetX, bottomRightY);
298
        g.drawLine(offsetX, 0, offsetX, bottomRightY);
264
        // Bottom
299
        // Bottom
265
        g.drawLine(0, bottomRightY, offsetX, bottomRightY);
300
        g.drawLine(0, bottomRightY, offsetX, bottomRightY);