Source Code Cross Referenced for DataEngineGraph.java in  » Report » FreeReportBuilder » it » frb » 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 » FreeReportBuilder » it.frb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright (C) 2004 Giuseppe MANNA
0003:         * 
0004:         * This file is part of FreeReportBuilder
0005:         * 
0006:         * FreeReportBuilder is free software; you can redistribute it and/or
0007:         * modify it under the terms of the GNU General Public License
0008:         * as published by the Free Software Foundation; either version 2
0009:         * of the License, or (at your option) any later version.
0010:         * 
0011:         * This program is distributed in the hope that it will be useful,
0012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014:         * GNU General Public License for more details.
0015:         * 
0016:         * You should have received a copy of the GNU General Public License
0017:         * along with this program; if not, write to the Free Software
0018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0019:         * 
0020:         */
0021:
0022:        package it.frb;
0023:
0024:        import java.awt.Component;
0025:        import java.sql.Connection;
0026:        import java.sql.SQLException;
0027:        import java.sql.Types;
0028:        import java.util.Vector;
0029:        import javax.swing.*;
0030:        import it.frb.*;
0031:        import java.awt.*;
0032:
0033:        public class DataEngineGraph implements  Runnable {
0034:            private boolean visibleRowsCountFrame = true;
0035:            private int chartType = Chart.BAR3D;
0036:            private java.sql.ResultSet rsDati;
0037:            private int maxHeight = 0;
0038:            private int maxWidth = 0;
0039:            private java.awt.Toolkit objToolkit;
0040:            private java.awt.Dimension dScSize;
0041:            private String sOutputGruppo = "";
0042:            private String[] arrayColumn = null;
0043:            private int[] arrayColumnType = null;
0044:            private String[] arrayColumnName = null;
0045:            private Connection connection;
0046:            private JPanel outPutPanel = null;
0047:            private java.util.Hashtable hashArgumentNested = null;
0048:            private java.sql.PreparedStatement pstmtQuery;
0049:            private java.sql.DatabaseMetaData dtmd;
0050:            private String execSql;
0051:            private DataPanel dataPanel;
0052:            private int counterColumnPos = 0;
0053:            private int cCPosForFinalTrailer = 0;
0054:            private int yHeightHeader = 0;
0055:            private int yTotalPosition = 0;
0056:            private int headerColumnPos = 0;
0057:            private boolean useResultSet = false;
0058:            private boolean bCloseSystem = false;
0059:            private boolean bExit = false;
0060:
0061:            private Vector vResultAxisX = new Vector();
0062:            private Vector vResultAxisY = new Vector();
0063:
0064:            private String useObj = "";
0065:            private String sSql = "";
0066:
0067:            public DataEngineGraph(Connection conn, DataPanel dataPanel)
0068:                    throws SQLException {
0069:                this (conn, dataPanel, "");
0070:            }
0071:
0072:            public DataEngineGraph(Connection conn, DataPanel dataPanel,
0073:                    String useObj) throws SQLException {
0074:                this .useObj = useObj;
0075:
0076:                objToolkit = java.awt.Toolkit.getDefaultToolkit();
0077:                dScSize = objToolkit.getScreenSize();
0078:
0079:                this .setConnection(conn);
0080:                this .initEngine(dataPanel);
0081:            }
0082:
0083:            public void initEngine(DataPanel dataPanel) throws SQLException {
0084:                this .dataPanel = dataPanel;
0085:                this .sSql = dataPanel.getSql();
0086:            }
0087:
0088:            public void setChartType(int chartType) {
0089:                this .chartType = chartType;
0090:            }
0091:
0092:            public int getChartType() {
0093:                return chartType;
0094:            }
0095:
0096:            public void setCloseSystem(boolean closeSystem) {
0097:                bCloseSystem = closeSystem;
0098:            }
0099:
0100:            public void run() {
0101:                try {
0102:                    this .retrieve();
0103:
0104:                    JPanel jChart = this .getOutputPanel();
0105:
0106:                    if (jChart != null) {
0107:                        JFrame jfResult = new JFrame();
0108:
0109:                        if (bCloseSystem) {
0110:                            jfResult
0111:                                    .addWindowListener(new java.awt.event.WindowAdapter() {
0112:                                        public void windowClosing(
0113:                                                java.awt.event.WindowEvent evt) {
0114:                                            System.exit(0);
0115:                                        }
0116:                                    });
0117:                            connection.close();
0118:                        }
0119:
0120:                        String sTitle = "";
0121:
0122:                        switch (chartType) {
0123:                        case Chart.BAR:
0124:                            sTitle = "Chart BAR";
0125:                            break;
0126:                        case Chart.BAR3D:
0127:                            sTitle = "Chart BAR 3D";
0128:                            break;
0129:                        case Chart.PIE:
0130:                            sTitle = "Chart PIE";
0131:                            break;
0132:                        case Chart.PIE3D:
0133:                            sTitle = "Chart PIE 3D";
0134:                            break;
0135:                        case Chart.XYLINE:
0136:                            sTitle = "Chart XY Line";
0137:                            break;
0138:                        }
0139:
0140:                        jfResult.setTitle(sTitle);
0141:
0142:                        int height = ConfigurationProperties.properties()
0143:                                .getWndHeight(
0144:                                        (int) java.awt.Toolkit
0145:                                                .getDefaultToolkit()
0146:                                                .getScreenSize().getHeight());
0147:                        int width = ConfigurationProperties.properties()
0148:                                .getWndWidth(
0149:                                        (int) java.awt.Toolkit
0150:                                                .getDefaultToolkit()
0151:                                                .getScreenSize().getWidth());
0152:
0153:                        int x = ConfigurationProperties.properties().getWndX(0);
0154:                        int y = ConfigurationProperties.properties().getWndY(0);
0155:
0156:                        jfResult.setBounds(x, y, width, height);
0157:                        jfResult.getContentPane().add(jChart,
0158:                                java.awt.BorderLayout.CENTER);
0159:
0160:                        jfResult.setVisible(true);
0161:
0162:                        java.awt.Toolkit.getDefaultToolkit().beep();
0163:                    }
0164:                } catch (SQLException sqlExc) {
0165:                    System.out.println("Errore SQL");
0166:                }
0167:            }
0168:
0169:            public JPanel retrieve() throws SQLException {
0170:                dataPanel.resetSqlForArgs();
0171:                dataPanel.resetArgsObject();
0172:
0173:                this .sSql = dataPanel.getSql();
0174:                execSql = this .prepareSql();
0175:
0176:                if (!sSql.equals("")) {
0177:                    int iIndex = sSql.indexOf("|");
0178:                    int iIndex2 = sSql.indexOf(":");
0179:
0180:                    if (connection != null) {
0181:                        if (iIndex == -1 || iIndex2 == -1) {
0182:                            dtmd = connection.getMetaData();
0183:
0184:                            useResultSet = ConfigurationProperties.properties()
0185:                                    .getUseResultSet(false);
0186:
0187:                            pstmtQuery = connection.prepareStatement(execSql);
0188:
0189:                            if (execute()) {
0190:                                outPutPanel.setBounds(0, 0, 2000,
0191:                                        yTotalPosition + 50);
0192:                            } else {
0193:                                outPutPanel = null;
0194:                            }
0195:
0196:                            return outPutPanel;
0197:                        } else {
0198:                            return this .retrieve(dataPanel.getArguments());
0199:                        }
0200:                    } else {
0201:                        JOptionPane.showMessageDialog(null, "No connection.");
0202:                    }
0203:                } else {
0204:                    JOptionPane
0205:                            .showMessageDialog(null,
0206:                                    "Attention is not present any query for this layout.");
0207:                }
0208:
0209:                return new JPanel();
0210:            }
0211:
0212:            public JPanel retrieve(Object args[]) throws SQLException {
0213:                if (args != null) {
0214:                    if (dataPanel.getSql().indexOf("?") == -1) {
0215:                        dataPanel.prepSqlWithArguments(args);
0216:                    }
0217:
0218:                    execSql = this .prepareSql();
0219:                    dtmd = connection.getMetaData();
0220:
0221:                    useResultSet = ConfigurationProperties.properties()
0222:                            .getUseResultSet(false);
0223:
0224:                    pstmtQuery = connection.prepareStatement(execSql);
0225:
0226:                    for (int i = 0; i < args.length; i++) {
0227:                        pstmtQuery.setObject(i + 1, args[i]);
0228:                    }
0229:
0230:                    if (execute()) {
0231:                        outPutPanel.setBounds(0, 0, 2000, yTotalPosition + 50);
0232:                    } else {
0233:                        outPutPanel = null;
0234:                    }
0235:                } else {
0236:                    return new JPanel();
0237:                }
0238:
0239:                return outPutPanel;
0240:            }
0241:
0242:            private boolean execute() throws SQLException {
0243:                boolean bexecute = false;
0244:
0245:                int count = dataPanel.getGroupCount();
0246:                yHeightHeader = dataPanel.getHeaderDividerRelativeLocation();
0247:                //outPutPanel   = new JPreviewPanel(dataPanel);
0248:
0249:                dataPanel.setSqlExecuted(execSql);
0250:                //outPutPanel.setSQLExecuted(execSql);
0251:
0252:                String sUltimiValoriGruppi[] = new String[count];
0253:
0254:                for (int i = 0; i < count; i++) {
0255:                    sUltimiValoriGruppi[i] = "";
0256:                }
0257:
0258:                //Finestrella per il contatore di righe
0259:                javax.swing.JFrame rowCountFrame = null;
0260:                java.net.URL imgIconURLOn = DataEngine.class
0261:                        .getResource("img/lighton.png");
0262:                java.awt.Image imLightOn = java.awt.Toolkit.getDefaultToolkit()
0263:                        .getImage(imgIconURLOn);
0264:                java.net.URL imgIconURLOff = DataEngine.class
0265:                        .getResource("img/lightoff.png");
0266:                java.awt.Image imLightOff = java.awt.Toolkit
0267:                        .getDefaultToolkit().getImage(imgIconURLOff);
0268:
0269:                if (visibleRowsCountFrame) {
0270:                    rowCountFrame = new javax.swing.JFrame();
0271:                    int delay = 250;
0272:                    it.frb.action.ActionTimer actionTimer = new it.frb.action.ActionTimer(
0273:                            rowCountFrame, imLightOn, imLightOff);
0274:                    new Timer(delay, actionTimer).start();
0275:                }
0276:
0277:                try {
0278:                    Vector vValueAxisX = new Vector();
0279:                    Vector vValueAxisY = new Vector();
0280:
0281:                    if (pstmtQuery.execute()) {
0282:                        hashArgumentNested = new java.util.Hashtable();
0283:                        rsDati = pstmtQuery.getResultSet();
0284:
0285:                        /* Header */
0286:                        JPanel jpHeader = dataPanel.getHeaderPanel();
0287:                        int BandHeightHeader = dataPanel
0288:                                .getHeaderDividerRelativeLocation();
0289:                        Component[] arrayHeaderCompPanel = jpHeader
0290:                                .getComponents();
0291:
0292:                        yTotalPosition = 0;
0293:                        int numRows = 0;
0294:                        int rowPage = 0;
0295:
0296:                        java.sql.ResultSetMetaData rsmd = rsDati.getMetaData();
0297:                        int columnCount = rsmd.getColumnCount();
0298:
0299:                        if (visibleRowsCountFrame) {
0300:                            javax.swing.JButton btn = new JButton("Stop");
0301:                            btn
0302:                                    .addMouseListener(new java.awt.event.MouseAdapter() {
0303:                                        public void mouseClicked(
0304:                                                java.awt.event.MouseEvent evt) {
0305:                                            DataEngineGraph.this .bExit = true;
0306:                                        }
0307:                                    });
0308:
0309:                            rowCountFrame.getContentPane().add(btn);
0310:                            rowCountFrame.setSize(220, 50);
0311:                            DataEngine
0312:                                    .centerWindow(rowCountFrame, SwingUtilities
0313:                                            .getWindowAncestor(dataPanel));
0314:                            rowCountFrame.setResizable(false);
0315:                            rowCountFrame.setVisible(true);
0316:                        }
0317:
0318:                        int indexvecTrailer;
0319:                        int trailerColumnPos = 0;
0320:                        boolean printHeader = true;
0321:
0322:                        Vector vWhereCompField = new Vector();
0323:                        Vector vTrailerValues = new Vector();
0324:
0325:                        while (rsDati.next() && !bExit) {
0326:                            //					if (printHeader)
0327:                            //					{
0328:                            //						this.loadComponentsOnPanel(arrayHeaderCompPanel, BandHeightHeader, 0);
0329:                            //						printHeader = false;
0330:                            //					}					
0331:
0332:                            counterColumnPos = headerColumnPos;
0333:
0334:                            for (int i = 1; i <= count; i++) {
0335:                                sOutputGruppo = "";
0336:                                String sWhereComputefield = "";
0337:
0338:                                int BandHeightComputedField = dataPanel
0339:                                        .getHeaderGroupDividerRelativeLocation(i);
0340:                                JPanel jpanelHeaderGroup = dataPanel
0341:                                        .getHeaderGroupPanel(i);
0342:                                Component[] arrayCompPanel = jpanelHeaderGroup
0343:                                        .getComponents();
0344:
0345:                                /* Gestione Componenti negli Header*/
0346:                                for (int j = 0; j < arrayCompPanel.length; j++) {
0347:                                    int BandHeight = dataPanel
0348:                                            .getHeaderGroupDividerRelativeLocation(i);
0349:                                    JComponent newComp = (JComponent) arrayCompPanel[j];
0350:
0351:                                    if ((newComp.getClass() == JTextField.class)) {
0352:                                        if (((JTextField) newComp).getName() == null
0353:                                                || ((JTextField) newComp)
0354:                                                        .getName().equals("")) {
0355:                                            counterColumnPos = counterColumnPos + 1;
0356:
0357:                                            int typeColumn = rsmd
0358:                                                    .getColumnType(counterColumnPos);
0359:
0360:                                            String sValoreForWhere = "";
0361:                                            String sValore = "";
0362:
0363:                                            if (typeColumn == Types.DATE
0364:                                                    || typeColumn == Types.TIME
0365:                                                    || typeColumn == Types.TIMESTAMP) {
0366:                                                java.sql.Timestamp date = rsDati
0367:                                                        .getTimestamp(counterColumnPos);
0368:
0369:                                                if (date != null) {
0370:                                                    sValore = date.toString();
0371:
0372:                                                    String days = sValore
0373:                                                            .substring(8, 10);
0374:                                                    String mounth = sValore
0375:                                                            .substring(5, 7);
0376:                                                    String year = sValore
0377:                                                            .substring(0, 4);
0378:
0379:                                                    sValoreForWhere = days
0380:                                                            + "/" + mounth
0381:                                                            + "/" + year;
0382:                                                } else {
0383:                                                    sValoreForWhere = "IS NULL";
0384:                                                }
0385:                                            } else {
0386:                                                sValore = rsDati
0387:                                                        .getString(counterColumnPos);
0388:                                                sValoreForWhere = sValore;
0389:                                            }
0390:
0391:                                            String columnName = ((JTextField) newComp)
0392:                                                    .getText();
0393:
0394:                                            if (typeColumn == Types.VARCHAR
0395:                                                    || typeColumn == Types.LONGVARCHAR
0396:                                                    || typeColumn == Types.CHAR
0397:                                                    || typeColumn == Types.DATE
0398:                                                    || typeColumn == Types.TIME
0399:                                                    || typeColumn == Types.TIMESTAMP
0400:                                                    || typeColumn == Types.OTHER) {
0401:                                                if (sValore != null
0402:                                                        && !sValore.equals("")) {
0403:                                                    if (sValore.indexOf("'") != -1) {
0404:                                                        sValoreForWhere = replaceString(
0405:                                                                sValore,
0406:                                                                new String("'"),
0407:                                                                new String("''"));
0408:                                                    }
0409:
0410:                                                    sWhereComputefield = sWhereComputefield
0411:                                                            + columnName
0412:                                                            + " = '"
0413:                                                            + sValoreForWhere
0414:                                                            + "' and ";
0415:                                                }
0416:                                            } else {
0417:                                                if (typeColumn == Types.BIGINT
0418:                                                        || typeColumn == Types.DECIMAL
0419:                                                        || typeColumn == Types.DOUBLE
0420:                                                        || typeColumn == Types.FLOAT
0421:                                                        || typeColumn == Types.INTEGER
0422:                                                        || typeColumn == Types.NUMERIC) {
0423:                                                    sWhereComputefield = sWhereComputefield
0424:                                                            + columnName
0425:                                                            + " = "
0426:                                                            + sValoreForWhere
0427:                                                            + " and ";
0428:                                                } else {
0429:                                                    if (sValore != null
0430:                                                            && !sValore
0431:                                                                    .equals("")) {
0432:                                                        if (sValore
0433:                                                                .indexOf("'") != -1) {
0434:                                                            sValoreForWhere = replaceString(
0435:                                                                    sValore,
0436:                                                                    new String(
0437:                                                                            "'"),
0438:                                                                    new String(
0439:                                                                            "''"));
0440:                                                        }
0441:
0442:                                                        sWhereComputefield = sWhereComputefield
0443:                                                                + columnName
0444:                                                                + " = '"
0445:                                                                + sValoreForWhere
0446:                                                                + "' and ";
0447:                                                    }
0448:                                                }
0449:                                            }
0450:
0451:                                            if (sValore != null) {
0452:                                                hashArgumentNested.put(
0453:                                                        ((JTextField) newComp)
0454:                                                                .getText(),
0455:                                                        sValore);
0456:                                                sValore = sValore.trim();
0457:                                                sOutputGruppo = sOutputGruppo
0458:                                                        + sValore;
0459:                                            }
0460:                                        }
0461:                                    }
0462:                                }
0463:
0464:                                if (!sOutputGruppo
0465:                                        .equals(sUltimiValoriGruppi[i - 1])) {
0466:                                    vValueAxisX.add(sOutputGruppo);
0467:
0468:                                    /* Gestione trailer (ricordarsi che questa sarebbe la gestione del)
0469:                                       trailer della riga precedente*/
0470:                                    if (sUltimiValoriGruppi[i - 1] != "") {
0471:                                        indexvecTrailer = 0;
0472:
0473:                                        for (int f = count; f >= i; f--) {
0474:                                            JPanel panelTrailer = dataPanel
0475:                                                    .getTrailerGroupPanel(f);
0476:                                            int BandHeight = dataPanel
0477:                                                    .getTrailerGroupDividerRelativeLocation(f);
0478:
0479:                                            Component[] arrayTrailerCompPanel = panelTrailer
0480:                                                    .getComponents();
0481:
0482:                                            for (int j = 0; j < arrayTrailerCompPanel.length; j++) {
0483:                                                JComponent jCompMove = (JComponent) arrayTrailerCompPanel[j];
0484:
0485:                                                updateDimensionPanel(jCompMove);
0486:
0487:                                                if ((jCompMove.getClass() != JTextField.class)) {
0488:
0489:                                                } else {
0490:                                                    if (((JTextField) jCompMove)
0491:                                                            .getName() == null
0492:                                                            || ((JTextField) jCompMove)
0493:                                                                    .getName()
0494:                                                                    .equals("")) {
0495:                                                        String sValore = (String) vTrailerValues
0496:                                                                .get(indexvecTrailer);
0497:                                                        indexvecTrailer = indexvecTrailer + 1;
0498:                                                        vValueAxisY
0499:                                                                .add(sValore);
0500:                                                    } else {
0501:                                                        String sWhere = "";
0502:                                                        int countCompute = f;
0503:
0504:                                                        while (countCompute != 0) {
0505:                                                            if (sWhere
0506:                                                                    .equals("")) {
0507:                                                                sWhere = (String) vWhereCompField
0508:                                                                        .get(countCompute - 1);
0509:                                                            } else {
0510:                                                                sWhere = sWhere
0511:                                                                        + " and "
0512:                                                                        + (String) vWhereCompField
0513:                                                                                .get(countCompute - 1);
0514:                                                            }
0515:
0516:                                                            countCompute = countCompute - 1;
0517:                                                        }
0518:
0519:                                                        String sOrderBy = "";
0520:
0521:                                                        if (f != 1) {
0522:                                                            sOrderBy = dataPanel
0523:                                                                    .getOrderByString(f);
0524:                                                        }
0525:
0526:                                                        String fromString = dataPanel
0527:                                                                .getFromString();
0528:
0529:                                                        ComputeField cmpField = null;
0530:
0531:                                                        if (!dataPanel
0532:                                                                .getWhereString()
0533:                                                                .equals("")) {
0534:                                                            cmpField = new ComputeField(
0535:                                                                    jCompMove,
0536:                                                                    fromString,
0537:                                                                    sWhere
0538:                                                                            + " and "
0539:                                                                            + dataPanel
0540:                                                                                    .getWhereString(),
0541:                                                                    sOrderBy,
0542:                                                                    dataPanel
0543:                                                                            .getArgsObject());
0544:                                                        } else {
0545:                                                            cmpField = new ComputeField(
0546:                                                                    jCompMove,
0547:                                                                    fromString,
0548:                                                                    sWhere,
0549:                                                                    sOrderBy,
0550:                                                                    dataPanel
0551:                                                                            .getArgsObject());
0552:                                                        }
0553:
0554:                                                        String valore = cmpField
0555:                                                                .getValue();
0556:                                                        vValueAxisY.add(valore);
0557:
0558:                                                    }
0559:                                                    /******************************/
0560:                                                }
0561:                                            }
0562:
0563:                                            yTotalPosition = yTotalPosition
0564:                                                    + dataPanel
0565:                                                            .getTrailerGroupDividerRelativeLocation(f);
0566:                                        }
0567:                                    }
0568:
0569:                                    if (!sWhereComputefield.equals("")) {
0570:                                        vWhereCompField.add(i - 1,
0571:                                                sWhereComputefield.substring(0,
0572:                                                        sWhereComputefield
0573:                                                                .length() - 4));
0574:                                    }
0575:
0576:                                    yTotalPosition = yTotalPosition
0577:                                            + dataPanel
0578:                                                    .getHeaderGroupDividerRelativeLocation(i);
0579:
0580:                                    sUltimiValoriGruppi[i - 1] = sOutputGruppo;
0581:
0582:                                    for (int w = i; w < count; w++) {
0583:                                        sUltimiValoriGruppi[w] = "";
0584:                                    }
0585:                                }
0586:                            }
0587:
0588:                            /* Inizio Dettaglio */
0589:                            JPanel jpanelDetail = dataPanel.getDetailPanel();
0590:                            Component[] arrayDetailCompPanel = jpanelDetail
0591:                                    .getComponents();
0592:                            for (int j = 0; j < arrayDetailCompPanel.length; j++) {
0593:                                int BandHeight = dataPanel
0594:                                        .getDetailDividerRelativeLocation();
0595:                                JComponent newComp = ((JComponent) arrayDetailCompPanel[j]);
0596:
0597:                                updateDimensionPanel(newComp);
0598:
0599:                                if ((newComp.getClass() == JTextField.class)) {
0600:                                    if (((JTextField) newComp).getName() == null
0601:                                            || ((JTextField) newComp).getName()
0602:                                                    .equals("")) {
0603:                                        counterColumnPos = counterColumnPos + 1;
0604:                                        String sValore = rsDati
0605:                                                .getString(counterColumnPos);
0606:
0607:                                        if (sValore != null) {
0608:                                            hashArgumentNested
0609:                                                    .put(((JTextField) newComp)
0610:                                                            .getText(), sValore);
0611:                                        }
0612:
0613:                                        if (j == 0) {
0614:                                            vValueAxisX.add(sValore);
0615:                                        } else {
0616:                                            vValueAxisY.add(sValore);
0617:                                        }
0618:                                    } else {
0619:                                        String sWhere = "";
0620:                                        int countCompute = count;
0621:
0622:                                        while (countCompute != 0) {
0623:                                            if (sWhere.equals("")) {
0624:                                                sWhere = (String) vWhereCompField
0625:                                                        .get(countCompute - 1);
0626:                                            } else {
0627:                                                sWhere = sWhere
0628:                                                        + " and "
0629:                                                        + (String) vWhereCompField
0630:                                                                .get(countCompute - 1);
0631:                                            }
0632:
0633:                                            countCompute = countCompute - 1;
0634:                                        }
0635:
0636:                                        String sOrderBy = "";
0637:
0638:                                        if (count != 1) {
0639:                                            sOrderBy = dataPanel
0640:                                                    .getOrderByString(count);
0641:                                        }
0642:
0643:                                        String fromString = dataPanel
0644:                                                .getFromString();
0645:
0646:                                        ComputeField cmpField = null;
0647:
0648:                                        if (!dataPanel.getWhereString().equals(
0649:                                                "")) {
0650:                                            cmpField = new ComputeField(
0651:                                                    newComp,
0652:                                                    fromString,
0653:                                                    sWhere
0654:                                                            + " and "
0655:                                                            + dataPanel
0656:                                                                    .getWhereString(),
0657:                                                    sOrderBy, dataPanel
0658:                                                            .getArgsObject());
0659:                                        } else {
0660:                                            cmpField = new ComputeField(
0661:                                                    newComp, fromString,
0662:                                                    sWhere, sOrderBy, dataPanel
0663:                                                            .getArgsObject());
0664:                                        }
0665:
0666:                                        String valore = cmpField.getValue();
0667:
0668:                                        if (j == 0) {
0669:                                            vValueAxisX.add(valore);
0670:                                        } else {
0671:                                            vValueAxisY.add(valore);
0672:                                        }
0673:                                    }
0674:                                }
0675:                            }
0676:
0677:                            vTrailerValues.clear();
0678:
0679:                            if (trailerColumnPos == 0) {
0680:                                trailerColumnPos = counterColumnPos;
0681:                            }
0682:
0683:                            //caricare il vettore dei trailer se ci sono altre colonne nel RecordSet
0684:                            for (int c = counterColumnPos; c <= columnCount - 1; c++) {
0685:                                counterColumnPos = counterColumnPos + 1;
0686:                                String sValore = rsDati
0687:                                        .getString(counterColumnPos);
0688:
0689:                                vTrailerValues.add(sValore);
0690:
0691:                                if (!useResultSet) {
0692:                                    arrayColumn[counterColumnPos - 1] = sValore;
0693:                                }
0694:                            }
0695:
0696:                            rowPage = numRows + 1;
0697:                            numRows = numRows + 1;
0698:
0699:                            if (visibleRowsCountFrame) {
0700:                                rowCountFrame.setTitle("Rows retrieved: "
0701:                                        + numRows);
0702:                            }
0703:                        }
0704:
0705:                        bExit = false;
0706:
0707:                        if (visibleRowsCountFrame) {
0708:                            rowCountFrame.setVisible(false);
0709:                            rowCountFrame = null;
0710:                        }
0711:
0712:                        if (numRows != 0) {
0713:                            /* Gestione trailer finali (perche' il ciclo while fa' rimanere
0714:                            indietro di uno i trailer)*/
0715:                            indexvecTrailer = 0;
0716:
0717:                            for (int f = count; f >= 1; f--) {
0718:                                if ((rowPage == numRows)
0719:                                        || !sOutputGruppo
0720:                                                .equals(sUltimiValoriGruppi[count - 1])) {
0721:                                    //gestione trailer finali
0722:                                    JPanel panelTrailer = dataPanel
0723:                                            .getTrailerGroupPanel(f);
0724:
0725:                                    int BandHeight = dataPanel
0726:                                            .getTrailerGroupDividerRelativeLocation(f);
0727:                                    Component[] arrayTrailerCompPanel = panelTrailer
0728:                                            .getComponents();
0729:
0730:                                    for (int j = 0; j < arrayTrailerCompPanel.length; j++) {
0731:                                        JComponent jCompMove = (JComponent) arrayTrailerCompPanel[j];
0732:
0733:                                        if ((jCompMove.getClass() != JTextField.class)) {
0734:
0735:                                        } else {
0736:                                            if (((JTextField) jCompMove)
0737:                                                    .getName() == null
0738:                                                    || ((JTextField) jCompMove)
0739:                                                            .getName().equals(
0740:                                                                    "")) {
0741:                                                String sValore = (String) vTrailerValues
0742:                                                        .get(indexvecTrailer);
0743:                                                indexvecTrailer = indexvecTrailer + 1;
0744:                                                vValueAxisY.add(sValore);
0745:                                            } else {
0746:                                                String sWhere = "";
0747:                                                int countCompute = f;
0748:
0749:                                                while (countCompute != 0) {
0750:                                                    if (sWhere.equals("")) {
0751:                                                        sWhere = (String) vWhereCompField
0752:                                                                .get(countCompute - 1);
0753:                                                    } else {
0754:                                                        sWhere = sWhere
0755:                                                                + " and "
0756:                                                                + (String) vWhereCompField
0757:                                                                        .get(countCompute - 1);
0758:                                                    }
0759:
0760:                                                    countCompute = countCompute - 1;
0761:                                                }
0762:
0763:                                                String sOrderBy = "";
0764:
0765:                                                if (f != 1) {
0766:                                                    sOrderBy = dataPanel
0767:                                                            .getOrderByString(f);
0768:                                                }
0769:
0770:                                                String fromString = dataPanel
0771:                                                        .getFromString();
0772:
0773:                                                ComputeField cmpField = null;
0774:
0775:                                                if (!dataPanel.getWhereString()
0776:                                                        .equals("")) {
0777:                                                    cmpField = new ComputeField(
0778:                                                            jCompMove,
0779:                                                            fromString,
0780:                                                            sWhere
0781:                                                                    + " and "
0782:                                                                    + dataPanel
0783:                                                                            .getWhereString(),
0784:                                                            sOrderBy,
0785:                                                            dataPanel
0786:                                                                    .getArgsObject());
0787:                                                } else {
0788:                                                    cmpField = new ComputeField(
0789:                                                            jCompMove,
0790:                                                            fromString,
0791:                                                            sWhere,
0792:                                                            sOrderBy,
0793:                                                            dataPanel
0794:                                                                    .getArgsObject());
0795:                                                }
0796:
0797:                                                String valore = cmpField
0798:                                                        .getValue();
0799:                                                vValueAxisY.add(valore);
0800:                                            }
0801:                                            /******************************/
0802:                                        }
0803:                                    }
0804:                                }
0805:                            }
0806:                        }
0807:
0808:                        if (useObj.equalsIgnoreCase("NEW")) {
0809:                            rsDati.getStatement().close();
0810:                        }
0811:                    }
0812:
0813:                    try {
0814:                        Chart chart = new Chart(vValueAxisX, vValueAxisY, this 
0815:                                .getChartType());
0816:                        outPutPanel = chart.getPanel();
0817:
0818:                        this .setResultOnAxisX(vValueAxisX);
0819:                        this .setResultOnAxisY(vValueAxisY);
0820:
0821:                        bexecute = true;
0822:
0823:                    } catch (NoClassDefFoundError ncde) {
0824:                        JOptionPane.showMessageDialog(SwingUtilities
0825:                                .getWindowAncestor(dataPanel),
0826:                                "Library JFreeChart not found down ./lib");
0827:                        bexecute = false;
0828:                    }
0829:
0830:                    return bexecute;
0831:
0832:                } catch (SQLException e) {
0833:                    if (rowCountFrame != null) {
0834:                        rowCountFrame.dispose();
0835:                    }
0836:
0837:                    JOptionPane.showMessageDialog(null, e.getMessage());
0838:
0839:                    if (rsDati != null) {
0840:                        rsDati.close();
0841:                    }
0842:
0843:                    connection.close();
0844:
0845:                    return bexecute;
0846:
0847:                } catch (ArrayIndexOutOfBoundsException e) {
0848:                    if (rowCountFrame != null) {
0849:                        rowCountFrame.dispose();
0850:                    }
0851:
0852:                    JOptionPane
0853:                            .showMessageDialog(
0854:                                    null,
0855:                                    "There is a problably error in the report.It checks if you have some groups, if in each there is at least a column.");
0856:
0857:                    if (rsDati != null) {
0858:                        rsDati.close();
0859:                    }
0860:
0861:                    connection.close();
0862:
0863:                    return bexecute;
0864:                }
0865:            }
0866:
0867:            public Vector getResultOnAxisX() {
0868:                return vResultAxisX;
0869:            }
0870:
0871:            public Vector getResultOnAxisY() {
0872:                return vResultAxisX;
0873:            }
0874:
0875:            public void setResultOnAxisX(Vector valuesAxisX) {
0876:                this .vResultAxisX = valuesAxisX;
0877:            }
0878:
0879:            public void setResultOnAxisY(Vector valuesAxisY) {
0880:                this .vResultAxisX = valuesAxisY;
0881:            }
0882:
0883:            private void updateDimensionPanel(JComponent obj) {
0884:                if ((obj.getLocation().x + obj.getSize().width) > maxWidth) {
0885:                    maxWidth = obj.getLocation().x + obj.getSize().width;
0886:                }
0887:
0888:                /*
0889:                if ((obj.getLocation().y + obj.getSize().height) > maxHeight)
0890:                {
0891:                  maxHeight = obj.getLocation().y + obj.getSize().height;
0892:                }
0893:                 */
0894:            }
0895:
0896:            private JComponent elementaryCopyJComponent(JComponent comp) {
0897:                JComponent obj = null;
0898:
0899:                try {
0900:                    obj = (JComponent) Class.forName(comp.getClass().getName())
0901:                            .newInstance();
0902:
0903:                } catch (ClassNotFoundException e) {
0904:                    System.out.println(e);
0905:
0906:                } catch (InstantiationException a) {
0907:                    System.out.println(a);
0908:
0909:                } catch (IllegalAccessException b) {
0910:                    System.out.println(b);
0911:                }
0912:
0913:                if (comp.getClass().getName() == "javax.swing.JSeparator") {
0914:                    ((javax.swing.JSeparator) obj)
0915:                            .setOrientation(((javax.swing.JSeparator) comp)
0916:                                    .getOrientation());
0917:                    ((javax.swing.JSeparator) obj)
0918:                            .setForeground(((javax.swing.JSeparator) comp)
0919:                                    .getForeground());
0920:                }
0921:
0922:                if (comp.getClass().getName() == "javax.swing.JLabel") {
0923:                    if (((JLabel) comp).getName() != null) {
0924:                        ((JLabel) obj).setName(((JLabel) comp).getName());
0925:                        ((JLabel) obj).setIcon(((JLabel) comp).getIcon());
0926:                    } else {
0927:                        ((JLabel) obj).setText(((JLabel) comp).getText());
0928:                        ((JLabel) obj).setFont(((JLabel) comp).getFont());
0929:                    }
0930:
0931:                    ((JLabel) obj).setForeground(((JLabel) comp)
0932:                            .getForeground());
0933:                }
0934:
0935:                if (comp.getClass().getName() == "javax.swing.JTextArea") {
0936:                    ((JTextArea) obj).setEditable(false);
0937:                    ((JTextArea) obj).setFont(((JTextArea) comp).getFont());
0938:                    ((JTextArea) obj).setForeground(((JTextArea) comp)
0939:                            .getForeground());
0940:                    ((JTextArea) obj).setBackground(((JTextArea) comp)
0941:                            .getBackground());
0942:                    ((JTextArea) obj).setLineWrap(((JTextArea) comp)
0943:                            .getLineWrap());
0944:                    ((JTextArea) obj).setText(((JTextArea) comp).getText());
0945:                }
0946:
0947:                return obj;
0948:            }
0949:
0950:            private Component[] arrayDuplicateComponents(Component[] arrJcomp) {
0951:                Component[] arrNewJComp = new Component[arrJcomp.length];
0952:
0953:                java.io.ObjectOutputStream o = null;
0954:                java.io.ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream();
0955:
0956:                try {
0957:                    o = new java.io.ObjectOutputStream(buf);
0958:
0959:                    for (int j = 0; j < arrJcomp.length; j++) {
0960:                        o.writeObject(arrJcomp[j]);
0961:                    }
0962:
0963:                    java.io.ObjectInputStream in = new java.io.ObjectInputStream(
0964:                            new java.io.ByteArrayInputStream(buf.toByteArray()));
0965:
0966:                    for (int j = 0; j < arrJcomp.length; j++) {
0967:                        JComponent newComp = (JComponent) in.readObject();
0968:                        arrNewJComp[j] = newComp;
0969:                    }
0970:
0971:                } catch (ClassNotFoundException e) {
0972:                    System.out.println(e.getMessage());
0973:
0974:                } catch (java.io.IOException i) {
0975:                    System.out.println(i.getMessage());
0976:                }
0977:
0978:                return arrNewJComp;
0979:            }
0980:
0981:            private static String replaceString(String strSource,
0982:                    String strFind, String strReplace) {
0983:                int indice = strSource.indexOf(strFind);
0984:
0985:                String returnValue = "";
0986:
0987:                if (indice >= 0) {
0988:                    String s = replace(new StringBuffer(strSource), indice,
0989:                            indice + strFind.length(), strReplace);
0990:                    if (indice + strFind.length() <= strSource.length()) {
0991:                        strSource = replaceString(strSource.substring(indice
0992:                                + strFind.length()), strFind, strReplace);
0993:                    } else {
0994:                        strSource = "";
0995:                    }
0996:
0997:                    if (strSource.equals("")) {
0998:                        returnValue = s;
0999:                    } else {
1000:                        returnValue = s.substring(0, indice + strFind.length()
1001:                                + 1)
1002:                                + strSource;
1003:                    }
1004:                }
1005:
1006:                return returnValue;
1007:            }
1008:
1009:            public static String replace(StringBuffer sbSource, int nStart,
1010:                    int nEnd, String sStr) {
1011:                String sHead = sbSource.toString().substring(0, nStart);
1012:                String sFoot = sbSource.toString().substring(nEnd);
1013:
1014:                StringBuffer sbRet = new StringBuffer(sHead);
1015:                sbRet.append(sStr);
1016:                sbRet.append(sFoot);
1017:
1018:                return sbRet.toString();
1019:            }
1020:
1021:            public static String replace(String sSource, int nStart, int nEnd,
1022:                    String sStr) {
1023:                String sHead = sSource.substring(0, nStart);
1024:                String sFoot = sSource.substring(nEnd);
1025:
1026:                StringBuffer sbRet = new StringBuffer(sHead);
1027:                sbRet.append(sStr);
1028:                sbRet.append(sFoot);
1029:
1030:                return sbRet.toString();
1031:            }
1032:
1033:            private String prepareSql() {
1034:                int iSelect = 0;
1035:
1036:                this .sSql = dataPanel.getSql().toUpperCase().trim().replace(
1037:                        '\n', ' ').replace('\t', ' ');
1038:                int iSelectDist = sSql.indexOf("SELECT DISTINCT ");
1039:
1040:                if (iSelectDist == -1) {
1041:                    iSelect = sSql.indexOf("SELECT ");
1042:                }
1043:
1044:                int iFrom = sSql.indexOf("FROM ");
1045:
1046:                if (iSelectDist != -1) {
1047:                    if (iSelectDist <= 16) {
1048:                        try {
1049:                            return DataEngine.replace(new StringBuffer(sSql),
1050:                                    iSelectDist + 16, iFrom, dataPanel
1051:                                            .getColumnSelect());
1052:
1053:                        } catch (Exception ex) {
1054:                            JOptionPane
1055:                                    .showMessageDialog(null,
1056:                                            "Attention, any column has not been inserted.");
1057:                            return "";
1058:                        }
1059:                    } else {
1060:                        return DataEngine
1061:                                .replace(new StringBuffer(sSql), iSelect + 7,
1062:                                        iFrom, dataPanel.getColumnSelect());
1063:                    }
1064:                } else {
1065:                    if (iSelect != -1) {
1066:                        try {
1067:                            return this .replace(new StringBuffer(this .sSql),
1068:                                    iSelect + 7, iFrom, dataPanel
1069:                                            .getColumnSelect());
1070:
1071:                        } catch (Exception ex) {
1072:                            JOptionPane
1073:                                    .showMessageDialog(null,
1074:                                            "Attention, any column has not been inserted.");
1075:                            return "";
1076:                        }
1077:                    } else {
1078:                        JOptionPane
1079:                                .showMessageDialog(null,
1080:                                        "Attention, the query has not correctly been written.");
1081:                        return "";
1082:                    }
1083:                }
1084:            }
1085:
1086:            public boolean getVisibleRowsCountFrame() {
1087:                return this .visibleRowsCountFrame;
1088:            }
1089:
1090:            public JPanel getOutputPanel() {
1091:                return outPutPanel;
1092:            }
1093:
1094:            public void setVisibleRowsCountFrame(boolean visible) {
1095:                this .visibleRowsCountFrame = visible;
1096:            }
1097:
1098:            public void setConnection(Connection conn) {
1099:                connection = conn;
1100:            }
1101:
1102:            public Connection getConnection() {
1103:                return connection;
1104:            }
1105:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.