Source Code Cross Referenced for CrosstabReportElement.java in  » Report » iReport-2.0.5 » it » businesslogic » ireport » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » iReport 2.0.5 » it.businesslogic.ireport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 - 2008 JasperSoft Corporation.  All rights reserved. 
003:         * http://www.jaspersoft.com.
004:         *
005:         * Unless you have purchased a commercial license agreement from JasperSoft,
006:         * the following license terms apply:
007:         *
008:         * This program is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU General Public License version 2 as published by
010:         * the Free Software Foundation.
011:         *
012:         * This program is distributed WITHOUT ANY WARRANTY; and without the
013:         * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014:         * See the GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018:         * or write to:
019:         *
020:         * Free Software Foundation, Inc.,
021:         * 59 Temple Place - Suite 330,
022:         * Boston, MA  USA  02111-1307
023:         *
024:         *
025:         *
026:         *
027:         * CrosstabReportElement.java
028:         * 
029:         * Created on 28 febbraio 2003, 22.53
030:         *
031:         */
032:
033:        package it.businesslogic.ireport;
034:
035:        import it.businesslogic.ireport.chart.Dataset;
036:        import it.businesslogic.ireport.crosstab.CrosstabCell;
037:        import it.businesslogic.ireport.crosstab.CrosstabColumnGroup;
038:        import it.businesslogic.ireport.crosstab.CrosstabGroup;
039:        import it.businesslogic.ireport.crosstab.CrosstabRowGroup;
040:        import it.businesslogic.ireport.crosstab.Measure;
041:        import it.businesslogic.ireport.gui.MainFrame;
042:        import it.businesslogic.ireport.gui.event.CrosstabLayoutChangedEvent;
043:        import it.businesslogic.ireport.util.*;
044:        import java.awt.*;
045:        import java.util.*;
046:
047:        public class CrosstabReportElement extends ReportElement {
048:
049:            private Report report = null;
050:
051:            private boolean repeatColumnHeaders = true;
052:            private boolean repeatRowHeaders = true;
053:            private int columnBreakOffset = 10;
054:            private Vector crosstabParameters = null;
055:            private String parametersMapExpression = "";
056:
057:            private String runDirection = "LTR";
058:
059:            public String getRunDirection() {
060:                return runDirection;
061:            }
062:
063:            public void setRunDirection(String runDirection) {
064:                this .runDirection = runDirection;
065:            }
066:
067:            // Crosstab properties...
068:            private boolean useDataset = false;
069:            private Dataset dataset = null;
070:            private boolean preSorted = false;
071:            private Vector measures = null;
072:
073:            private Vector rowGroups = new Vector();
074:            private Vector columnGroups = new Vector();
075:            private Vector elements = new Vector();
076:
077:            private Vector cells = new Vector();
078:
079:            public static Image img = null;
080:
081:            public CrosstabReportElement(int x, int y, int width, int height) {
082:                super (x, y, width, height);
083:                setKey("crosstab");
084:
085:                dataset = new Dataset();
086:                crosstabParameters = new Vector();
087:                measures = new Vector();
088:
089:                if (img == null)
090:                    img = Misc.loadBufferedImageFromResources(
091:                            new java.awt.Panel(),
092:                            "it/businesslogic/ireport/icons/crosstabTool1.png");
093:            }
094:
095:            public void drawObject(Graphics2D g, double zoom_factor,
096:                    int x_shift_origin, int y_shift_origin) {
097:
098:                position.x -= 10;
099:                position.y -= 10;
100:                x_shift_origin -= 10;
101:                y_shift_origin -= 10;
102:
103:                this .zoom_factor = zoom_factor;
104:
105:                Color ccc = new Color(204, 204, 204, 150);
106:
107:                g.setColor(ccc);
108:                Paint paint = g.getPaint();
109:                g.setPaint(new GradientPaint(getZoomedDim(position.x)
110:                        - x_shift_origin, getZoomedDim(position.y)
111:                        - y_shift_origin, ccc, getZoomedDim(position.x)
112:                        - x_shift_origin + getZoomedDim(width),
113:                        getZoomedDim(position.x) - x_shift_origin
114:                                + getZoomedDim(height), ccc.brighter()));
115:
116:                g.fillRect(getZoomedDim(position.x) - x_shift_origin,
117:                        getZoomedDim(position.y) - y_shift_origin,
118:                        getZoomedDim(width), getZoomedDim(height));
119:                g.setPaint(paint);
120:
121:                position.x += 10;
122:                position.y += 10;
123:                x_shift_origin += 10;
124:                y_shift_origin += 10;
125:
126:                drawGraphicsElement(g, zoom_factor, x_shift_origin,
127:                        y_shift_origin);
128:            }
129:
130:            public void drawGraphicsElement(Graphics2D g, double zoom_factor,
131:                    int x_shift_origin, int y_shift_origin) {
132:                drawGraphicsElement(g, "Thin", zoom_factor, x_shift_origin,
133:                        y_shift_origin);
134:                int correction = 0; //(zoom_factor <= 1) ? -1 : 0;
135:
136:                position.x -= 10;
137:                position.y -= 10;
138:                x_shift_origin -= 10;
139:                y_shift_origin -= 10;
140:
141:                if (img != null) {/*
142:                                    g.drawImage(img, 
143:                                        getZoomedDim(position.x)-x_shift_origin,
144:                                        getZoomedDim(position.y)-y_shift_origin,
145:                                        getZoomedDim(width)+correction,getZoomedDim(height)+correction, null);
146:                 */
147:                    int imageWidth = img.getWidth(null);
148:                    int imageHeight = img.getHeight(null);
149:                    /*
150:                    if (imgx instanceof Image)
151:                    {
152:                    ((Image)imgx).setTransparent(true);
153:                    }
154:                     */
155:
156:                    // 
157:                    if (imageWidth < width && imageHeight < height) {
158:                        Rectangle destination = new Rectangle(
159:                                getZoomedDim(position.x) - x_shift_origin,
160:                                getZoomedDim(position.y) - y_shift_origin,
161:                                getZoomedDim(imageWidth),
162:                                getZoomedDim(imageHeight - 1));
163:                        Rectangle source = new Rectangle(0, 0, imageWidth,
164:                                imageHeight);
165:                        // Calculate y shift based on hAlign...
166:                        int elem_height = getZoomedDim(this .height);
167:                        elem_height -= getZoomedDim(imageHeight);
168:                        // Calculate x shift based on hAlign...
169:                        int elem_width = getZoomedDim(this .width);
170:                        elem_width -= getZoomedDim(imageWidth);
171:                        g.drawImage(img, destination.x + 1, destination.y + 1,
172:                                destination.x + destination.width + 1,
173:                                destination.y + destination.height + 1,
174:                                source.x, source.y, source.width,
175:                                source.height, null, null);
176:                    } else if (width > 0 && height > 0)// Resize based on minor x/WIDTH... e y/HEIGHT
177:                    {
178:                        if ((double) ((double) imageWidth / (double) width) > (double) ((double) imageHeight / (double) height)) {
179:
180:                            Rectangle source = new Rectangle(0, 0, imageWidth,
181:                                    imageHeight);
182:                            Rectangle destination = new Rectangle(
183:                                    getZoomedDim(position.x) - x_shift_origin,
184:                                    getZoomedDim(position.y) - y_shift_origin,
185:                                    getZoomedDim(width), getZoomedDim(Math.min(
186:                                            (imageHeight * width) / imageWidth,
187:                                            height - 1)));
188:
189:                            // Calculate y shift based on hAlign...
190:                            int elem_height = getZoomedDim(this .height);
191:                            elem_height -= getZoomedDim(Math.min(
192:                                    (imageHeight * width) / imageWidth, height));
193:
194:                            g.drawImage(img, destination.x + 1,
195:                                    destination.y + 1, destination.x
196:                                            + destination.width, destination.y
197:                                            + destination.height, source.x,
198:                                    source.y, source.width, source.height,
199:                                    null, null);
200:                        } else {
201:                            Rectangle source = new Rectangle(0, 0, imageWidth,
202:                                    imageHeight);
203:                            Rectangle destination = new Rectangle(
204:                                    getZoomedDim(position.x) - x_shift_origin,
205:                                    getZoomedDim(position.y) - y_shift_origin,
206:                                    getZoomedDim(Math.min((imageWidth * height)
207:                                            / imageHeight, width)),
208:                                    getZoomedDim(height - 1));
209:
210:                            // Calculate x shift based on hAlign...
211:                            int elem_width = getZoomedDim(this .width);
212:                            elem_width -= getZoomedDim(Math.min(
213:                                    (imageWidth * height) / imageHeight, width));
214:
215:                            g.drawImage(img, destination.x + 1,
216:                                    destination.y + 1, destination.x
217:                                            + destination.width, destination.y
218:                                            + destination.height, source.x,
219:                                    source.y, source.width, source.height,
220:                                    null, null);
221:                        }
222:                    }
223:                }
224:                position.x += 10;
225:                position.y += 10;
226:            }
227:
228:            public ReportElement cloneMe() {
229:                CrosstabReportElement newReportElement = new CrosstabReportElement(
230:                        position.x, position.y, width, height);
231:                copyBaseReportElement(newReportElement, this );
232:                return newReportElement;
233:            }
234:
235:            public void copyBaseReportElement(ReportElement destination,
236:                    ReportElement source) {
237:                super .copyBaseReportElement(destination, source);
238:
239:                if (destination instanceof  CrosstabReportElement
240:                        && source instanceof  CrosstabReportElement) {
241:
242:                    /*
243:                    ((SubReportElement)destination).setIsUsingCache( ((SubReportElement)source).isIsUsingCache());
244:                    ((SubReportElement)destination).setParametersMapExpression( new String(  ((SubReportElement)source).getParametersMapExpression() ));
245:                    ((SubReportElement)destination).setSubreportExpression ( new String(  ((SubReportElement)source).getSubreportExpression() ));
246:                    ((SubReportElement)destination).setSubreportExpressionClass( new String(  ((SubReportElement)source).getSubreportExpressionClass() ));
247:                    ((SubReportElement)destination).setUseConnection(  ((SubReportElement)source).isUseConnection() );
248:                    if ( ((SubReportElement)destination).isUseConnection())
249:                        ((SubReportElement)destination).setConnectionExpression(  new String( ((SubReportElement)source).getConnectionExpression() ));
250:                    else
251:                        ((SubReportElement)destination).setDataSourceExpression( new String(  ((SubReportElement)source).getDataSourceExpression() ));
252:                    
253:                    Enumeration e = ((SubReportElement)source).getSubreportParameters().elements();
254:                    while (e.hasMoreElements())
255:                    {
256:                    JRSubreportParameter jp = (JRSubreportParameter)e.nextElement();
257:                    ((SubReportElement)destination).getSubreportParameters().addElement(jp.cloneMe());
258:                    }	
259:                     */
260:                }
261:            }
262:
263:            public boolean isRepeatColumnHeaders() {
264:                return repeatColumnHeaders;
265:            }
266:
267:            public void setRepeatColumnHeaders(boolean repeatColumnHeaders) {
268:                if (this .repeatColumnHeaders == repeatColumnHeaders)
269:                    return;
270:                this .columnBreakOffset = columnBreakOffset;
271:                notifyChange();
272:            }
273:
274:            public boolean isRepeatRowHeaders() {
275:                return repeatRowHeaders;
276:            }
277:
278:            public int getColumnBreakOffset() {
279:                return columnBreakOffset;
280:            }
281:
282:            public Vector getCrosstabParameters() {
283:                return crosstabParameters;
284:            }
285:
286:            public String getParametersMapExpression() {
287:                return parametersMapExpression;
288:            }
289:
290:            public void setParametersMapExpression(
291:                    String parametersMapExpression) {
292:
293:                if ((this .parametersMapExpression == null) ? parametersMapExpression == null
294:                        : this .parametersMapExpression
295:                                .equals(parametersMapExpression))
296:                    return;
297:                this .parametersMapExpression = parametersMapExpression;
298:                notifyChange();
299:            }
300:
301:            public void setColumnBreakOffset(int columnBreakOffset) {
302:                if (this .columnBreakOffset == columnBreakOffset)
303:                    return;
304:                this .columnBreakOffset = columnBreakOffset;
305:                notifyChange();
306:            }
307:
308:            public void setRepeatRowHeaders(boolean repeatRowHeaders) {
309:                if (this .repeatRowHeaders == repeatRowHeaders)
310:                    return;
311:                this .repeatRowHeaders = repeatRowHeaders;
312:                notifyChange();
313:            }
314:
315:            public Dataset getDataset() {
316:                return dataset;
317:            }
318:
319:            public void setDataset(Dataset dataset) {
320:                if (this .dataset == dataset)
321:                    return;
322:                this .dataset = dataset;
323:                notifyChange();
324:            }
325:
326:            public boolean isUseDataset() {
327:                return useDataset;
328:            }
329:
330:            public void setUseDataset(boolean useDataset) {
331:                if (this .useDataset == useDataset)
332:                    return;
333:                this .useDataset = useDataset;
334:                notifyChange();
335:            }
336:
337:            public boolean isPreSorted() {
338:                return preSorted;
339:            }
340:
341:            public void setPreSorted(boolean preSorted) {
342:                if (this .preSorted == preSorted)
343:                    return;
344:                this .preSorted = preSorted;
345:                notifyChange();
346:
347:            }
348:
349:            public Vector getMeasures() {
350:                return measures;
351:            }
352:
353:            public void setMeasures(Vector measures) {
354:                this .measures = measures;
355:            }
356:
357:            public Vector getRowGroups() {
358:                return rowGroups;
359:            }
360:
361:            public void setRowGroups(Vector rowGroups) {
362:                this .rowGroups = rowGroups;
363:            }
364:
365:            public Vector getColumnGroups() {
366:                return columnGroups;
367:            }
368:
369:            public void setColumnGroups(Vector columnGroups) {
370:                this .columnGroups = columnGroups;
371:            }
372:
373:            public Vector getElements() {
374:                return elements;
375:            }
376:
377:            public void setElements(Vector elements) {
378:                this .elements = elements;
379:            }
380:
381:            public Vector getCells() {
382:                return cells;
383:            }
384:
385:            public void setCells(Vector cells) {
386:                this .cells = cells;
387:            }
388:
389:            /**
390:             * Utility field used by event firing mechanism.
391:             */
392:            private javax.swing.event.EventListenerList listenerList = null;
393:
394:            /**
395:             * Registers CrosstabLayoutChangedListener to receive events.
396:             * @param listener The listener to register.
397:             */
398:            public synchronized void addCrosstabLayoutChangedListener(
399:                    it.businesslogic.ireport.gui.event.CrosstabLayoutChangedListener listener) {
400:
401:                if (listenerList == null) {
402:                    listenerList = new javax.swing.event.EventListenerList();
403:                }
404:                listenerList
405:                        .add(
406:                                it.businesslogic.ireport.gui.event.CrosstabLayoutChangedListener.class,
407:                                listener);
408:            }
409:
410:            /**
411:             * Removes CrosstabLayoutChangedListener from the list of listeners.
412:             * @param listener The listener to remove.
413:             */
414:            public synchronized void removeCrosstabLayoutChangedListener(
415:                    it.businesslogic.ireport.gui.event.CrosstabLayoutChangedListener listener) {
416:
417:                listenerList
418:                        .remove(
419:                                it.businesslogic.ireport.gui.event.CrosstabLayoutChangedListener.class,
420:                                listener);
421:            }
422:
423:            /**
424:             * Notifies all registered listeners about the event.
425:             * 
426:             * @param event The event to be fired
427:             */
428:            public void fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(
429:                    it.businesslogic.ireport.gui.event.CrosstabLayoutChangedEvent event) {
430:
431:                if (listenerList == null)
432:                    return;
433:                Object[] listeners = listenerList.getListenerList();
434:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
435:                    if (listeners[i] == it.businesslogic.ireport.gui.event.CrosstabLayoutChangedListener.class) {
436:                        ((it.businesslogic.ireport.gui.event.CrosstabLayoutChangedListener) listeners[i + 1])
437:                                .crosstabLayoutChanged(event);
438:                    }
439:                }
440:            }
441:
442:            /**
443:             * Notifies all registered listeners about the event.
444:             * 
445:             * @param event The event to be fired
446:             */
447:            public void fireCrosstabMeasureChangedListenerCrosstabLayoutChanged(
448:                    it.businesslogic.ireport.gui.event.CrosstabLayoutChangedEvent event) {
449:
450:                if (listenerList == null)
451:                    return;
452:                Object[] listeners = listenerList.getListenerList();
453:                for (int i = listeners.length - 2; i >= 0; i -= 2) {
454:                    if (listeners[i] == it.businesslogic.ireport.gui.event.CrosstabLayoutChangedListener.class) {
455:                        ((it.businesslogic.ireport.gui.event.CrosstabLayoutChangedListener) listeners[i + 1])
456:                                .crosstabMeasureChanged(event);
457:                    }
458:                }
459:            }
460:
461:            /**
462:             * Add safetly a groups from a CrosstabRowGroup and fires a CrosstabLayoutChangedEvent.
463:             */
464:            public void addGroup(CrosstabRowGroup group) {
465:                CrosstabCell headerCell = new CrosstabCell();
466:                headerCell.setName(group.getName() + " header");
467:                headerCell.setType(CrosstabCell.HEADER_CELL);
468:                headerCell.setWidth(group.getWidth());
469:                //if (!group.isHasHeader()) headerCell.setHeight(0);
470:                group.setHeaderCell(headerCell);
471:
472:                CrosstabCell totalHeaderCell = new CrosstabCell();
473:                totalHeaderCell.setName(group.getName() + " total header");
474:                totalHeaderCell.setType(CrosstabCell.HEADER_CELL);
475:                totalHeaderCell.setWidth(group.getWidth());
476:                if (group.getTotalPosition().equals("None")) {
477:                    totalHeaderCell.setHeight(0);
478:                } else {
479:                    totalHeaderCell.setHeight(30);
480:                }
481:                group.setTotalCell(totalHeaderCell);
482:
483:                //intln("set total height to "  +totalHeaderCell.getHeight() + " position total: '" + group.getTotalPosition()+"'");
484:
485:                this .getCells().add(group.getHeaderCell());
486:                this .getCells().add(group.getTotalCell());
487:
488:                // We have to add a default cell... Detail / Column...
489:                CrosstabCell cell = new CrosstabCell();
490:                cell.setType(cell.DETAIL_CELL);
491:                cell.setParent(this );
492:                cell.setName(null);
493:                cell.setRowTotalGroup(group.getName());
494:                if (group.getTotalPosition().equals("None"))
495:                    cell.setHeight(0);
496:                else
497:                    cell.setHeight(30);
498:
499:                this .getCells().add(cell);
500:
501:                this .getRowGroups().add(group);
502:
503:                fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(
504:                        this , this ));
505:                notifyChange();
506:            }
507:
508:            /**
509:             * Add safetly a groups from a CrosstabColumnGroup and fires a CrosstabLayoutChangedEvent.
510:             */
511:            public void addGroup(CrosstabColumnGroup group) {
512:                CrosstabCell headerCell = new CrosstabCell();
513:                headerCell.setName(group.getName() + " header");
514:                headerCell.setType(CrosstabCell.HEADER_CELL);
515:                headerCell.setParent(this );
516:                headerCell.setHeight(group.getHeight());
517:                group.setHeaderCell(headerCell);
518:
519:                CrosstabCell totalHeaderCell = new CrosstabCell();
520:                totalHeaderCell.setName(group.getName() + " total header");
521:                totalHeaderCell.setType(CrosstabCell.HEADER_CELL);
522:                totalHeaderCell.setParent(this );
523:                totalHeaderCell.setHeight(group.getHeight());
524:                if (group.getTotalPosition().equals("None"))
525:                    totalHeaderCell.setWidth(0);
526:                else
527:                    totalHeaderCell.setWidth(30);
528:                group.setTotalCell(totalHeaderCell);
529:
530:                this .getCells().add(group.getHeaderCell());
531:                this .getCells().add(group.getTotalCell());
532:
533:                // We have to add a default cell... Detail / Column...
534:                CrosstabCell cell = new CrosstabCell();
535:                cell.setType(cell.DETAIL_CELL);
536:                cell.setParent(this );
537:                cell.setColumnTotalGroup(group.getName());
538:                if (group.getTotalPosition().equals("None"))
539:                    cell.setWidth(0);
540:                else
541:                    cell.setWidth(30);
542:                this .getCells().add(cell);
543:
544:                this .getColumnGroups().add(group);
545:
546:                fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(
547:                        this , this ));
548:                notifyChange();
549:            }
550:
551:            /**
552:             * Remove safetly a set of groups from a Crosstab and fires a CrosstabLayoutChangedEvent.
553:             */
554:            public void removeGroups(Collection groups) {
555:                Iterator i_groups = groups.iterator();
556:                while (i_groups.hasNext()) {
557:                    CrosstabGroup group = (CrosstabGroup) i_groups.next();
558:
559:                    removeCell(group.getHeaderCell());
560:                    removeCell(group.getTotalCell());
561:
562:                    for (int i = 0; i < getCells().size(); ++i) {
563:                        CrosstabCell cell = (CrosstabCell) getCells()
564:                                .elementAt(i);
565:                        if (cell.getColumnTotalGroup().equals(group.getName())
566:                                || cell.getRowTotalGroup().equals(
567:                                        group.getName())) {
568:                            i -= removeCell(cell) ? 1 : 0;
569:                        }
570:                    }
571:
572:                    if (group instanceof  CrosstabRowGroup)
573:                        this .getRowGroups().remove(group);
574:                    if (group instanceof  CrosstabColumnGroup)
575:                        this .getColumnGroups().remove(group);
576:                }
577:                fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(
578:                        this , this ));
579:                notifyChange();
580:            }
581:
582:            /**
583:             * Remove safetly a group from a Crosstab and fires a CrosstabLayoutChangedEvent.
584:             */
585:            public void removeGroup(CrosstabGroup group) {
586:                if (group == null)
587:                    return;
588:                ArrayList v = new ArrayList();
589:                v.add(group);
590:                removeGroups(v);
591:                notifyChange();
592:            }
593:
594:            public void addMeasure(Measure measure) {
595:                getMeasures().addElement(measure);
596:                fireCrosstabMeasureChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(
597:                        this , this ));
598:                notifyChange();
599:            }
600:
601:            public void measureModified(Measure measure) {
602:                fireCrosstabMeasureChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(
603:                        this , this ));
604:                notifyChange();
605:            }
606:
607:            public void removeMeasure(Measure measure) {
608:                getMeasures().removeElement(measure);
609:                fireCrosstabMeasureChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(
610:                        this , this ));
611:                notifyChange();
612:            }
613:
614:            public void modifyGroup(String oldGroupName, CrosstabRowGroup group) {
615:
616:                group.getHeaderCell().setWidth(group.getWidth());
617:                group.getTotalCell().setWidth(group.getWidth());
618:
619:                if (!group.isHasHeader()) {
620:                    for (int i = 0; i < getElements().size(); ++i) {
621:                        ReportElement re = (ReportElement) getElements()
622:                                .elementAt(i);
623:                        if (re.getCell() == group.getHeaderCell()) {
624:                            i -= getElements().remove(re) ? 1 : 0;
625:                        }
626:                        group.getHeaderCell().setBox(new Box());
627:                        group.getHeaderCell().setBackcolor(null);
628:                    }
629:                }
630:
631:                if (!group.isHasTotal()) {
632:                    group.getTotalCell().setHeight(0);
633:                } else if (group.getTotalCell().getHeight() == 0) {
634:                    group.getTotalCell().setHeight(30);
635:                }
636:
637:                // 1. Rename all cells...
638:                Iterator i = getCells().iterator();
639:                while (i.hasNext()) {
640:                    CrosstabCell cell = (CrosstabCell) i.next();
641:                    if (cell.getRowTotalGroup().equals(oldGroupName)) {
642:                        cell.setRowTotalGroup(group.getName());
643:                        if (!group.isHasTotal()) {
644:                            cell.setHeight(0);
645:                            // Remove all cell elements..
646:                            for (int t = 0; t < getElements().size(); ++t) {
647:                                ReportElement re = (ReportElement) getElements()
648:                                        .elementAt(t);
649:                                if (re.getCell() == cell) {
650:                                    t -= getElements().remove(re) ? 1 : 0;
651:                                }
652:                            }
653:                        } else if (cell.getHeight() == 0) {
654:                            cell.setHeight(30);
655:                        }
656:                    }
657:                }
658:
659:                fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(
660:                        this , this ));
661:                notifyChange();
662:            }
663:
664:            public void modifyGroup(String oldGroupName,
665:                    CrosstabColumnGroup group) {
666:
667:                group.getHeaderCell().setHeight(group.getHeight());
668:                group.getTotalCell().setHeight(group.getHeight());
669:
670:                if (!group.isHasHeader()) {
671:                    for (int i = 0; i < getElements().size(); ++i) {
672:                        ReportElement re = (ReportElement) getElements()
673:                                .elementAt(i);
674:                        if (re.getCell() == group.getHeaderCell()) {
675:                            i -= getElements().remove(re) ? 1 : 0;
676:                        }
677:                        group.getHeaderCell().setBox(new Box());
678:                        group.getHeaderCell().setBackcolor(null);
679:                    }
680:                }
681:
682:                if (!group.isHasTotal()) {
683:                    group.getTotalCell().setWidth(0);
684:                } else if (group.getTotalCell().getWidth() == 0) {
685:                    group.getTotalCell().setWidth(30);
686:                }
687:
688:                // 1. Rename all cells...
689:                Iterator i = getCells().iterator();
690:                while (i.hasNext()) {
691:                    CrosstabCell cell = (CrosstabCell) i.next();
692:                    if (cell.getColumnTotalGroup().equals(oldGroupName)) {
693:                        cell.setColumnTotalGroup(group.getName());
694:                        if (!group.isHasTotal()) {
695:                            cell.setWidth(0);
696:                            // Remove all cell elements..
697:                            for (int t = 0; t < getElements().size(); ++t) {
698:                                ReportElement re = (ReportElement) getElements()
699:                                        .elementAt(t);
700:                                if (re.getCell() == cell) {
701:                                    t -= getElements().remove(re) ? 1 : 0;
702:                                }
703:                            }
704:                        } else if (cell.getWidth() == 0) {
705:                            cell.setWidth(30);
706:                        }
707:                    }
708:                }
709:
710:                fireCrosstabLayoutChangedListenerCrosstabLayoutChanged(new CrosstabLayoutChangedEvent(
711:                        this , this ));
712:                notifyChange();
713:            }
714:
715:            /**
716:             * This method remove the cell and all contained elements
717:             */
718:            private boolean removeCell(CrosstabCell cell) {
719:                for (int i = 0; i < getElements().size(); ++i) {
720:                    ReportElement re = (ReportElement) getElements().elementAt(
721:                            i);
722:                    if (re.getCell() == cell) {
723:                        i -= getElements().remove(re) ? 1 : 0;
724:                    }
725:                }
726:                notifyChange();
727:                return getCells().remove(cell);
728:            }
729:
730:            public Point trasform(Point delta, int type) {
731:                Point point = super .trasform(delta, type);
732:
733:                try {
734:
735:                    if (MainFrame.getMainInstance().getActiveReportFrame() != null) {
736:                        MainFrame.getMainInstance().getActiveReportFrame()
737:                                .getCrosstabEditor(this ).getPanelEditor()
738:                                .updateGrid();
739:                    }
740:                } catch (Exception ex) {
741:                }
742:
743:                return point;
744:            }
745:
746:            public Report getReport() {
747:                return report;
748:            }
749:
750:            public void setReport(Report report) {
751:                this .report = report;
752:            }
753:
754:            public void notifyChange() {
755:                if (getReport() != null) {
756:                    getReport().incrementReportChanges();
757:                }
758:            }
759:
760:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.