Source Code Cross Referenced for RBReporter.java in  » Internationalization-Localization » RBManager » com » ibm » rbm » 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 » Internationalization Localization » RBManager » com.ibm.rbm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *****************************************************************************
0003:         * Copyright (C) 2000-2004, International Business Machines Corporation and  *
0004:         * others. All Rights Reserved.                                              *
0005:         *****************************************************************************
0006:         */
0007:        package com.ibm.rbm;
0008:
0009:        import javax.swing.*;
0010:        import java.awt.*;
0011:        import java.awt.event.*;
0012:        import java.io.*;
0013:        import java.util.*;
0014:
0015:        import org.apache.xerces.dom.DocumentImpl;
0016:        import org.apache.xml.serialize.*;
0017:        import org.w3c.dom.*;
0018:
0019:        import com.ibm.rbm.gui.RBManagerGUI;
0020:
0021:        /**
0022:         * RBReporter is a fully functional application that runs separate from RBManager.
0023:         * The report produces statistically based reports on specified resource bundles,
0024:         * and it allows the user to set time intervals at which those reports will be
0025:         * generated. For more information on command line arguments and usage see the
0026:         * comments for the main() method.
0027:         * 
0028:         * @author Jared Jackson
0029:         * @see com.ibm.rbm.RBManager
0030:         */
0031:        public class RBReporter extends JFrame {
0032:
0033:            // ** COMPONENTS **
0034:            JLabel statusLabel; // Indicates if the reported is running
0035:            JButton statusButton; // Button for toggling the reporter on/off
0036:            JLabel nextReportLabel; // Indicates date/time of next report
0037:            JLabel lastReportLabel; // Indicates date/time of last report
0038:            JTextField bundleField; // Indicates input base class file
0039:            JTextField directoryField; // Indicates output directory
0040:            JCheckBox textCheck; // Is text report generated?
0041:            JCheckBox htmlCheck; // Is HTML report generated?
0042:            JCheckBox xmlCheck; // Is XML report generated?
0043:            JCheckBox scanCheck; // Is code scan performed?
0044:            JTextField textField; // Text report file name
0045:            JTextField htmlField; // HTML report file name
0046:            JTextField xmlField; // XML report file name
0047:            JTextField scanField; // XML scanner file location
0048:            JComboBox textCombo; // Text report detail level
0049:            JComboBox htmlCombo; // HTML report detail level
0050:            JComboBox xmlCombo; // XML report detail level
0051:            JRadioButton sequentialRadio; // Report at sequential interval?
0052:            JRadioButton definedRadio; // Report at defined time?
0053:            JComboBox valueCombo; // Number of units to wait between reports
0054:            JComboBox unitCombo; // Units of time
0055:            JComboBox hourCombo; // Defined time to report -- hours
0056:            JComboBox minuteCombo; // Defined time to report -- minutes
0057:            JComboBox dayCombo; // Defined time to report -- day
0058:
0059:            // ** File Chooser **
0060:            JFileChooser bundleFileChooser = new JFileChooser();
0061:            JFileChooser directoryFileChooser = new JFileChooser();
0062:            JFileChooser scanFileChooser = new JFileChooser();
0063:
0064:            // ** DATA **
0065:            Date lastReport = null;
0066:            Date nextReport = null;
0067:            boolean running = false;
0068:            /** For generating a report */
0069:            RBManager rbm;
0070:
0071:            private RBReporter(boolean makeVisible) {
0072:                try {
0073:                    // Get the look and feel from preferences	
0074:                    try {
0075:                        String laf = Preferences.getPreference("lookandfeel");
0076:                        if (!laf.equals(""))
0077:                            UIManager.setLookAndFeel(laf);
0078:                    } catch (Exception e) {
0079:                    }
0080:                    // Get the locale from preferences
0081:                    if (!Preferences.getPreference("locale").equals("")) {
0082:                        String localeStr = Preferences.getPreference("locale");
0083:                        String language = Resources.getLanguage(localeStr);
0084:                        String country = Resources.getCountry(localeStr);
0085:                        String variant = Resources.getVariant(localeStr);
0086:                        if (language == null || language.equals("")
0087:                                || language.length() > 3)
0088:                            language = "en";
0089:                        if (country == null)
0090:                            country = new String();
0091:                        if (variant == null)
0092:                            Resources.setLocale(new Locale(language, country));
0093:                        else
0094:                            Resources.setLocale(new Locale(language, country,
0095:                                    variant));
0096:                    }
0097:                    Resources.initBundle();
0098:                } catch (Exception e) {
0099:                    e.printStackTrace();
0100:                }
0101:                initComponents();
0102:                setVisible(makeVisible);
0103:                Thread reportThread = new Thread() {
0104:                    public void run() {
0105:                        if (nextReport != null
0106:                                && (nextReport.compareTo(new Date()) <= 0)) {
0107:                            try {
0108:                                generateReports();
0109:                            } catch (IOException ioe) {
0110:                            }
0111:                        }
0112:                        if (nextReport == null)
0113:                            nextReport = generateNextReportDate();
0114:                        updateStatusComponents();
0115:                        updateDateFields();
0116:                        while (true) {
0117:                            if (running
0118:                                    && (nextReport.compareTo(new Date()) < 0)) {
0119:                                try {
0120:                                    generateReports();
0121:                                } catch (IOException ioe) {
0122:                                    JOptionPane.showMessageDialog(null, ioe
0123:                                            .getMessage(), Resources
0124:                                            .getTranslation("error"),
0125:                                            JOptionPane.ERROR_MESSAGE);
0126:                                }
0127:                            }
0128:                            try {
0129:                                sleep(1000);
0130:                            } catch (Exception e) {
0131:                                e.printStackTrace(System.err);
0132:                            }
0133:                        }
0134:                    }
0135:                };
0136:                reportThread.start();
0137:            }
0138:
0139:            // Called when a report should be generated. Does not check if it should be generated
0140:            private void generateReports() throws IOException {
0141:                File baseFile = new File(bundleField.getText());
0142:                if (baseFile == null || !baseFile.isFile())
0143:                    throw new IOException("Specified input file is unusable");
0144:                File directory = new File(directoryField.getText());
0145:                rbm = new RBManager(baseFile);
0146:
0147:                if (rbm == null)
0148:                    throw new IOException(
0149:                            "Unable to load the resource bundle file");
0150:                if (directory == null || !directory.isDirectory())
0151:                    throw new IOException(
0152:                            "Specified output directory is unusable");
0153:                RBReporterScanner scanner = null;
0154:                if (scanCheck.isSelected()) {
0155:                    scanner = new RBReporterScanner((Bundle) rbm.getBundles()
0156:                            .elementAt(0), new File(scanField.getText()));
0157:                    scanner.performScan();
0158:                }
0159:                if (textCheck.isSelected()) {
0160:                    File textFile = new File(directory, textField.getText());
0161:                    String textReport = getAllLanguageReports(textCombo
0162:                            .getSelectedIndex() == 0);
0163:                    if (scanCheck.isSelected()) {
0164:                        // Add file scan information
0165:                        StringBuffer buffer = new StringBuffer();
0166:                        buffer.append("\n\nCode Scan Results:\n\n");
0167:                        buffer.append("\n\tNumber of unique resources found: "
0168:                                + scanner.getNumberResourcesFound());
0169:                        buffer
0170:                                .append("\n\tNumber of resources missing from bundle: "
0171:                                        + scanner.getNumberMissingResources());
0172:                        // Missing resources from the bundle
0173:                        buffer.append("\n\tMissing Resources: ");
0174:                        Vector v = scanner.getMissingResources();
0175:                        for (int i = 0; i < v.size(); i++) {
0176:                            ScanResult result = (ScanResult) v.elementAt(i);
0177:                            if (textCombo.getSelectedIndex() == 0) {
0178:                                buffer.append("\n\t\t" + result.getName()
0179:                                        + " (" + result.getOccurances().size()
0180:                                        + " Occurances)");
0181:                                buffer.append("\n\t\t\t"
0182:                                        + result.getOccurances());
0183:                            } else {
0184:                                buffer.append((i == 0 ? "" : ", ")
0185:                                        + result.getName() + " ("
0186:                                        + result.getOccurances().size()
0187:                                        + " Occurances)");
0188:                            }
0189:                        }
0190:                        // Bundle resources not found in the code
0191:                        buffer
0192:                                .append("\n\tNumber of potentially unused resources in bundle: "
0193:                                        + scanner.getNumberUnusedResources());
0194:                        v = scanner.getUnusedResources();
0195:                        for (int i = 0; i < v.size(); i++) {
0196:                            ScanResult result = (ScanResult) v.elementAt(i);
0197:                            if (textCombo.getSelectedIndex() == 0) {
0198:                                buffer.append("\n\t\t" + result.getName()
0199:                                        + " (Group: " + result.getGroupName()
0200:                                        + ")");
0201:                            } else {
0202:                                buffer.append((i == 0 ? "" : ", ")
0203:                                        + result.getName());
0204:                            }
0205:                        }
0206:
0207:                        textReport = textReport + buffer.toString();
0208:                    }
0209:                    FileWriter fw = new FileWriter(textFile);
0210:                    fw.write(textReport);
0211:                    fw.flush();
0212:                    fw.close();
0213:                }
0214:                if (htmlCheck.isSelected()) {
0215:                    File htmlFile = new File(directory, htmlField.getText());
0216:                    Document htmlReport = getHTMLReportz(htmlCombo
0217:                            .getSelectedIndex() == 0);
0218:                    if (scanCheck.isSelected()) {
0219:                        // Add file scan information
0220:                        Element html_elem = htmlReport.getDocumentElement();
0221:                        NodeList nl = html_elem.getElementsByTagName("BODY");
0222:                        Element body_elem = (Element) nl.item(0);
0223:                        Element h2_elem = htmlReport.createElement("H2");
0224:                        Text h2_text = htmlReport
0225:                                .createTextNode("Code Scan Results");
0226:                        Element block_elem = htmlReport
0227:                                .createElement("BLOCKQUOTE");
0228:                        Element p1_elem = htmlReport.createElement("P");
0229:                        Element p2_elem = htmlReport.createElement("P");
0230:                        Element p3_elem = htmlReport.createElement("P");
0231:                        Text p1_text = htmlReport
0232:                                .createTextNode("Number of unique resources found: "
0233:                                        + scanner.getNumberMissingResources());
0234:                        Text p2_text = htmlReport
0235:                                .createTextNode("Number of resources missing from bundle: "
0236:                                        + scanner.getNumberMissingResources());
0237:                        Text p3_text = htmlReport
0238:                                .createTextNode("Number of potentially unused resources in bundle: "
0239:                                        + scanner.getNumberUnusedResources());
0240:
0241:                        h2_elem.appendChild(h2_text);
0242:                        p1_elem.appendChild(p1_text);
0243:                        p2_elem.appendChild(p2_text);
0244:                        p3_elem.appendChild(p3_text);
0245:                        block_elem.appendChild(p1_elem);
0246:                        block_elem.appendChild(p2_elem);
0247:                        block_elem.appendChild(p3_elem);
0248:                        body_elem.appendChild(h2_elem);
0249:                        body_elem.appendChild(block_elem);
0250:
0251:                        // Missing resources from the bundle
0252:                        Text missing_text = null;
0253:                        Vector v = scanner.getMissingResources();
0254:                        if (htmlCombo.getSelectedIndex() == 0) {
0255:                            Element ul_elem = htmlReport.createElement("UL");
0256:                            missing_text = htmlReport
0257:                                    .createTextNode("Missing Resources:");
0258:                            ul_elem.appendChild(missing_text);
0259:                            for (int i = 0; i < v.size(); i++) {
0260:                                ScanResult result = (ScanResult) v.elementAt(i);
0261:                                Element li_elem = htmlReport
0262:                                        .createElement("LI");
0263:                                Element br_elem = htmlReport
0264:                                        .createElement("BR");
0265:                                Text t1_text = htmlReport.createTextNode(result
0266:                                        .getName()
0267:                                        + " ("
0268:                                        + result.getOccurances().size()
0269:                                        + " Occurances)");
0270:                                Text t2_text = htmlReport.createTextNode(result
0271:                                        .getOccurances().toString());
0272:                                li_elem.appendChild(t1_text);
0273:                                li_elem.appendChild(br_elem);
0274:                                li_elem.appendChild(t2_text);
0275:                                ul_elem.appendChild(li_elem);
0276:                            }
0277:                            p2_elem.appendChild(ul_elem);
0278:                        } else {
0279:                            StringBuffer buffer = new StringBuffer();
0280:                            buffer.append("Missing Resources: ");
0281:                            for (int i = 0; i < v.size(); i++) {
0282:                                ScanResult result = (ScanResult) v.elementAt(i);
0283:                                buffer.append((i == 0 ? "" : ", ")
0284:                                        + result.getName() + " ("
0285:                                        + result.getOccurances().size()
0286:                                        + " Occurances)");
0287:                            }
0288:                            missing_text = htmlReport.createTextNode(buffer
0289:                                    .toString());
0290:                            Element br_elem = htmlReport.createElement("BR");
0291:                            p2_elem.appendChild(br_elem);
0292:                            p2_elem.appendChild(missing_text);
0293:                        }
0294:                        // Bundle resources not found in the code
0295:                        Text unused_text = null;
0296:                        v = scanner.getUnusedResources();
0297:                        if (htmlCombo.getSelectedIndex() == 0) {
0298:                            Element ul_elem = htmlReport.createElement("UL");
0299:                            unused_text = htmlReport
0300:                                    .createTextNode("Unused Resources:");
0301:                            ul_elem.appendChild(unused_text);
0302:                            for (int i = 0; i < v.size(); i++) {
0303:                                ScanResult result = (ScanResult) v.elementAt(i);
0304:                                Element li_elem = htmlReport
0305:                                        .createElement("LI");
0306:                                Text t1_text = htmlReport.createTextNode(result
0307:                                        .getName()
0308:                                        + " (Group: "
0309:                                        + result.getGroupName()
0310:                                        + ")");
0311:                                li_elem.appendChild(t1_text);
0312:                                ul_elem.appendChild(li_elem);
0313:                            }
0314:                            p3_elem.appendChild(ul_elem);
0315:                        } else {
0316:                            StringBuffer buffer = new StringBuffer();
0317:                            buffer.append("Unused Resources: ");
0318:                            for (int i = 0; i < v.size(); i++) {
0319:                                ScanResult result = (ScanResult) v.elementAt(i);
0320:                                buffer.append((i == 0 ? "" : ", ")
0321:                                        + result.getName());
0322:                            }
0323:                            unused_text = htmlReport.createTextNode(buffer
0324:                                    .toString());
0325:                            Element br_elem = htmlReport.createElement("BR");
0326:                            p3_elem.appendChild(br_elem);
0327:                            p3_elem.appendChild(unused_text);
0328:                        }
0329:                    }
0330:                    FileWriter fw = new FileWriter(htmlFile);
0331:                    OutputFormat of = new OutputFormat(htmlReport);
0332:                    of.setIndenting(true);
0333:                    of.setEncoding("ISO-8859-1");
0334:                    HTMLSerializer serializer = new HTMLSerializer(fw, of);
0335:                    serializer.serialize(htmlReport);
0336:                }
0337:                if (xmlCheck.isSelected()) {
0338:                    File xmlFile = new File(directory, xmlField.getText());
0339:                    Document xmlReport = getXMLReportz(xmlCombo
0340:                            .getSelectedIndex() == 0);
0341:                    if (scanCheck.isSelected()) {
0342:                        // Add file scan information
0343:                        Element root = xmlReport.getDocumentElement();
0344:                        Element code_scan_elem = xmlReport
0345:                                .createElement("CODE_SCAN");
0346:                        Element unique_elem = xmlReport
0347:                                .createElement("UNIQUE_RESOURCES");
0348:                        Element missing_elem = xmlReport
0349:                                .createElement("MISSING_RESOURCES");
0350:                        Element unused_elem = xmlReport
0351:                                .createElement("UNUSED_RESOURCES");
0352:                        Element unique_total_elem = xmlReport
0353:                                .createElement("TOTAL");
0354:                        Element missing_total_elem = xmlReport
0355:                                .createElement("TOTAL");
0356:                        Element unused_total_elem = xmlReport
0357:                                .createElement("TOTAL");
0358:                        Text unique_total_text = xmlReport
0359:                                .createTextNode(String.valueOf(scanner
0360:                                        .getNumberMissingResources()));
0361:                        Text missing_total_text = xmlReport
0362:                                .createTextNode(String.valueOf(scanner
0363:                                        .getNumberMissingResources()));
0364:                        Text unused_total_text = xmlReport
0365:                                .createTextNode(String.valueOf(scanner
0366:                                        .getNumberUnusedResources()));
0367:
0368:                        unique_total_elem.appendChild(unique_total_text);
0369:                        missing_total_elem.appendChild(missing_total_text);
0370:                        unused_total_elem.appendChild(unused_total_text);
0371:                        unique_elem.appendChild(unique_total_elem);
0372:                        missing_elem.appendChild(missing_total_elem);
0373:                        unused_elem.appendChild(unused_total_elem);
0374:                        code_scan_elem.appendChild(unique_elem);
0375:                        code_scan_elem.appendChild(missing_elem);
0376:                        code_scan_elem.appendChild(unused_elem);
0377:                        root.appendChild(code_scan_elem);
0378:                        // Missing resources from the bundle
0379:                        Vector v = scanner.getMissingResources();
0380:                        for (int i = 0; i < v.size(); i++) {
0381:                            ScanResult result = (ScanResult) v.elementAt(i);
0382:                            Element item_elem = xmlReport
0383:                                    .createElement("RESOURCE");
0384:                            item_elem.setAttribute("NAME", result.getName());
0385:                            if (xmlCombo.getSelectedIndex() == 0) {
0386:                                Vector occ_v = result.getOccurances();
0387:                                for (int j = 0; j < occ_v.size(); j++) {
0388:                                    Occurance occ = (Occurance) occ_v
0389:                                            .elementAt(j);
0390:                                    Element occ_elem = xmlReport
0391:                                            .createElement("OCCURANCE");
0392:                                    occ_elem.setAttribute("FILE_NAME", occ
0393:                                            .getFileName());
0394:                                    occ_elem.setAttribute("FILE_PATH", occ
0395:                                            .getFilePath());
0396:                                    occ_elem.setAttribute("LINE_NUMBER", String
0397:                                            .valueOf(occ.getLineNumber()));
0398:                                    item_elem.appendChild(occ_elem);
0399:                                }
0400:                            }
0401:                            missing_elem.appendChild(item_elem);
0402:                        }
0403:                        // Bundle resources not found in the code
0404:                        v = scanner.getUnusedResources();
0405:                        for (int i = 0; i < v.size(); i++) {
0406:                            ScanResult result = (ScanResult) v.elementAt(i);
0407:                            Element item_elem = xmlReport
0408:                                    .createElement("RESOURCE");
0409:                            item_elem.setAttribute("NAME", result.getName());
0410:                            item_elem.setAttribute("GROUP", result
0411:                                    .getGroupName());
0412:                            unused_elem.appendChild(item_elem);
0413:                        }
0414:                    }
0415:                    FileWriter fw = new FileWriter(xmlFile);
0416:                    OutputFormat of = new OutputFormat(xmlReport);
0417:                    of.setIndenting(true);
0418:                    of.setEncoding("ISO-8859-1");
0419:                    XMLSerializer serializer = new XMLSerializer(fw, of);
0420:                    serializer.serialize(xmlReport);
0421:                }
0422:
0423:                lastReport = new Date();
0424:                nextReport = generateNextReportDate();
0425:                updateDateFields();
0426:                if (!isVisible()) {
0427:                    System.out.println("RBReporter: Generated report at "
0428:                            + lastReport.toString());
0429:                    System.out.println("RBReporter: Next report at "
0430:                            + nextReport.toString());
0431:                }
0432:            }
0433:
0434:            // Assumes the last report was just generated, and computes the next report time accordingly
0435:            private Date generateNextReportDate() {
0436:                Date retDate = null;
0437:                GregorianCalendar now = new GregorianCalendar();
0438:                if (sequentialRadio.isSelected()) {
0439:                    int value = Integer.parseInt(valueCombo.getSelectedItem()
0440:                            .toString());
0441:                    if (unitCombo.getSelectedIndex() == 0)
0442:                        now.add(Calendar.MINUTE, value);
0443:                    else if (unitCombo.getSelectedIndex() == 1)
0444:                        now.add(Calendar.HOUR, value);
0445:                    else if (unitCombo.getSelectedIndex() == 2)
0446:                        now.add(Calendar.DATE, value);
0447:                    retDate = now.getTime();
0448:                } else if (definedRadio.isSelected()) {
0449:                    int hour = Integer.parseInt(hourCombo.getSelectedItem()
0450:                            .toString());
0451:                    int minute = Integer.parseInt(minuteCombo.getSelectedItem()
0452:                            .toString());
0453:                    int day = dayCombo.getSelectedIndex();
0454:
0455:                    GregorianCalendar then = new GregorianCalendar();
0456:                    then.set(Calendar.HOUR, hour);
0457:                    then.set(Calendar.MINUTE, minute);
0458:                    then.set(Calendar.SECOND, 0);
0459:
0460:                    if (then.getTime().compareTo(now.getTime()) <= 0)
0461:                        then.add(Calendar.DATE, 1);
0462:                    if (day > 0 && day <= 7) {
0463:                        // Make sure we are at the right day
0464:                        boolean rightDay = false;
0465:                        while (!rightDay) {
0466:                            int weekDay = then.get(Calendar.DAY_OF_WEEK);
0467:                            if ((day == 1 && weekDay == Calendar.MONDAY)
0468:                                    || (day == 2 && weekDay == Calendar.TUESDAY)
0469:                                    || (day == 3 && weekDay == Calendar.WEDNESDAY)
0470:                                    || (day == 4 && weekDay == Calendar.THURSDAY)
0471:                                    || (day == 5 && weekDay == Calendar.FRIDAY)
0472:                                    || (day == 6 && weekDay == Calendar.SATURDAY)
0473:                                    || (day == 7 && weekDay == Calendar.SUNDAY))
0474:                                rightDay = true;
0475:                            else
0476:                                then.add(Calendar.DATE, 1);
0477:                        }
0478:                    }
0479:                    retDate = then.getTime();
0480:                }
0481:                RBManagerGUI.debugMsg("Next Date: " + retDate.toString());
0482:                return retDate;
0483:            }
0484:
0485:            /**
0486:             * Returns a string based text report about all of the language files on record
0487:             */
0488:            public String getAllLanguageReports(boolean detailed) {
0489:                String retStr = new String();
0490:                retStr = "Resource Bundle Report: " + rbm.getBaseClass();
0491:                retStr += "\nReport Generated:       "
0492:                        + (new Date()).toString() + "\n\n";
0493:                Vector bundles = rbm.getBundles();
0494:                for (int i = 0; i < bundles.size(); i++) {
0495:                    retStr += getLanguageReport(detailed, (Bundle) bundles
0496:                            .elementAt(i));
0497:                }
0498:                return retStr;
0499:            }
0500:
0501:            private String getLanguageReport(boolean detailed, Bundle dict) {
0502:        if (dict == null) return "";
0503:        String retStr = new String();
0504:        retStr += "\nLanguage: " + (dict.language == null ? dict.encoding : dict.language);
0505:        retStr += (dict.country == null ? "" : " - Country: " + dict.country);
0506:        retStr += (dict.variant == null ? "" : " - Variant: " + dict.variant);
0507:        retStr += "\n";
0508:        retStr += "  Number of NLS items in the file: " + dict.allItems.size() + "\n";
0509:		
0510:        int untranslated = 0;
0511:        String untransStr = new String();
0512:        Enumeration enum = dict.allItems.elements();
0513:        while (enum.hasMoreElements()) {
0514:            BundleItem tempItem = (BundleItem)enum.nextElement();
0515:            if (tempItem.isTranslated()) continue;
0516:            untranslated++;
0517:            untransStr += " " + tempItem.getKey();
0518:        }
0519:        retStr += "  Number of NLS items not translated: " + untranslated;
0520:        if (detailed) {
0521:            retStr += "\n  Untranslated NLS keys: " + untransStr;	
0522:        }
0523:		
0524:        return retStr;
0525:    }
0526:
0527:            /**
0528:             * Returns an XHTML formatted report on the status of the currently opened resource bundle
0529:             */
0530:            public Document getHTMLReportz(boolean detailed) {
0531:                Document html = new DocumentImpl();
0532:                Element root = html.createElement("HTML");
0533:                html.appendChild(root);
0534:                Element head_elem = html.createElement("HEAD");
0535:                Element title_elem = html.createElement("TITLE");
0536:                Text title_text = html
0537:                        .createTextNode("Resource Bundle Report - "
0538:                                + rbm.getBaseClass());
0539:                Element body_elem = html.createElement("BODY");
0540:                Element center1_elem = html.createElement("CENTER");
0541:                Element h1_elem = html.createElement("H1");
0542:                Element center2_elem = html.createElement("CENTER");
0543:                Element h3_elem = html.createElement("H1");
0544:                Text title1_text = html
0545:                        .createTextNode("Resource Bundle Report: "
0546:                                + rbm.getBaseClass());
0547:                Text title2_text = html.createTextNode("Report Generated: "
0548:                        + (new Date()).toString());
0549:                Vector bundles = rbm.getBundles();
0550:
0551:                title_elem.appendChild(title_text);
0552:                head_elem.appendChild(title_elem);
0553:                h1_elem.appendChild(title1_text);
0554:                h3_elem.appendChild(title2_text);
0555:                center1_elem.appendChild(h1_elem);
0556:                center2_elem.appendChild(h3_elem);
0557:                body_elem.appendChild(center1_elem);
0558:                body_elem.appendChild(center2_elem);
0559:                root.appendChild(head_elem);
0560:                root.appendChild(body_elem);
0561:
0562:                for (int i = 0; i < bundles.size(); i++) {
0563:                    getHTMLLanguageReportz(html, body_elem, detailed,
0564:                            (Bundle) bundles.elementAt(i));
0565:                }
0566:
0567:                return html;
0568:            }
0569:
0570:            /**
0571:             * Returns a HTML report as a String object on the status of the currently opened resource bundle
0572:             */
0573:            public String getHTMLReport(boolean detailed) {
0574:                StringBuffer buffer = new StringBuffer();
0575:                buffer.append("<HTML>\n<HEAD><TITLE>Resource Bundle Report - "
0576:                        + rbm.getBaseClass() + "</TITLE></HEAD>\n<BODY>\n");
0577:                buffer.append("<CENTER><H1>Resource Bundle Report: "
0578:                        + rbm.getBaseClass() + "</H1></CENTER>\n");
0579:                buffer.append("<CENTER><H3>Report Generated: "
0580:                        + (new Date()).toString() + "</H3></CENTER>\n");
0581:
0582:                Vector bundles = rbm.getBundles();
0583:                for (int i = 0; i < bundles.size(); i++) {
0584:                    buffer.append(getHTMLLanguageReport(detailed,
0585:                            (Bundle) bundles.elementAt(i)));
0586:                }
0587:
0588:                buffer.append("</BODY>\n</HTML>");
0589:                return buffer.toString();
0590:            }
0591:
0592:            private void getHTMLLanguageReportz(Document html, Element body_elem, boolean detailed, Bundle dict) {
0593:        Element h2_elem = html.createElement("H2");
0594:        Text    h2_text = html.createTextNode("Language: " + (dict.language == null ? dict.encoding : dict.language) +
0595:                          (dict.country == null ? "" : " - Country: " + dict.country) +
0596:                          (dict.variant == null ? "" : " - Variant: " + dict.variant));
0597:        Element block_elem = html.createElement("BLOCKQUOTE");
0598:        Element p_elem = html.createElement("P");
0599:        Text    p_text = html.createTextNode("Number of NLS items in the file: " +
0600:                         String.valueOf(dict.allItems.size()));
0601:        Element ul_elem = html.createElement("UL");
0602:        Text    ul_text = html.createTextNode("Untranslated NLS keys:");
0603:		
0604:        h2_elem.appendChild(h2_text);
0605:        p_elem.appendChild(p_text);
0606:        ul_elem.appendChild(ul_text);
0607:        block_elem.appendChild(p_elem);
0608:        body_elem.appendChild(h2_elem);
0609:        body_elem.appendChild(block_elem);
0610:		
0611:        int untranslated = 0;
0612:        Enumeration enum = dict.allItems.elements();
0613:        while (enum.hasMoreElements()) {
0614:            BundleItem tempItem = (BundleItem)enum.nextElement();
0615:            if (tempItem.isTranslated()) continue;
0616:            untranslated++;
0617:            if (detailed) {
0618:                Element li_elem = html.createElement("LI");
0619:                Text    li_text = html.createTextNode(tempItem.getKey());
0620:                li_elem.appendChild(li_text);
0621:                ul_elem.appendChild(li_elem);
0622:            }
0623:        }
0624:        Element p2_elem = html.createElement("P");
0625:        Text    p2_text = html.createTextNode("Number of NLS items not translated: " +
0626:                          String.valueOf(untranslated));
0627:        p2_elem.appendChild(p2_text);
0628:        block_elem.appendChild(p2_elem);
0629:        if (detailed) block_elem.appendChild(ul_elem);
0630:    }
0631:
0632:            private String getHTMLLanguageReport(boolean detailed, Bundle dict) {
0633:        StringBuffer buffer = new StringBuffer();
0634:        buffer.append("\n<H2>Language: " + (dict.language == null ? dict.encoding : dict.language));
0635:        buffer.append(dict.country == null ? "" : " - Country: " + dict.country);
0636:        buffer.append(dict.variant == null ? "" : " - Variant: " + dict.variant);
0637:        buffer.append("</H2>\n");
0638:        buffer.append("<BLOCKQUOTE>\n");
0639:        
0640:        buffer.append("<P>Number of NLS items in the file: " + String.valueOf(dict.allItems.size()) + "</P>\n");
0641:        int untranslated = 0;
0642:        Enumeration enum = dict.allItems.elements();
0643:        StringBuffer innerBuffer = new StringBuffer();
0644:        while (enum.hasMoreElements()) {
0645:            BundleItem tempItem = (BundleItem)enum.nextElement();
0646:            if (tempItem.isTranslated()) continue;
0647:            untranslated++;
0648:            innerBuffer.append("<LI>" + tempItem.getKey() + "</LI>\n");
0649:        }
0650:        buffer.append("<P>Number of NLS items not translated: " + String.valueOf(untranslated) + "</P>\n");
0651:        if (detailed) {
0652:            buffer.append("<UL>Untranslated NLS keys:\n");
0653:            buffer.append(innerBuffer.toString());
0654:            buffer.append("</UL>\n");
0655:        }
0656:		
0657:        buffer.append("</BLOCKQUOTE>\n");
0658:        return buffer.toString();
0659:    }
0660:
0661:            /**
0662:             * Returns an XML formatted report on the status of the currently open resource bundle
0663:             */
0664:
0665:            public Document getXMLReportz(boolean detailed) {
0666:                Document xml = new DocumentImpl();
0667:                Element root = xml.createElement("REPORT");
0668:                root.setAttribute("BASECLASS", rbm.getBaseClass());
0669:                root.setAttribute("DATE", (new Date()).toString());
0670:                xml.appendChild(root);
0671:
0672:                Vector bundles = rbm.getBundles();
0673:                for (int i = 0; i < bundles.size(); i++) {
0674:                    root.appendChild(getXMLLanguageReportz(xml, detailed,
0675:                            (Bundle) bundles.elementAt(i)));
0676:                }
0677:                return xml;
0678:            }
0679:
0680:            /**
0681:             * Returns an XML formatted report as a String object on the status of the currently open resource bundle
0682:             */
0683:
0684:            public String getXMLReport(boolean detailed) {
0685:                StringBuffer buffer = new StringBuffer();
0686:                buffer.append("<?xml version=\"1.0\"?>\n");
0687:                buffer.append("<REPORT BASECLASS=\"" + rbm.getBaseClass()
0688:                        + "\" DATE=\"" + (new Date()).toString() + "\">\n");
0689:
0690:                Vector bundles = rbm.getBundles();
0691:                for (int i = 0; i < bundles.size(); i++) {
0692:                    buffer.append(getXMLLanguageReport(detailed,
0693:                            (Bundle) bundles.elementAt(i)));
0694:                }
0695:                buffer.append("</REPORT>");
0696:                return buffer.toString();
0697:            }
0698:
0699:            private Element getXMLLanguageReportz(Document xml, boolean detailed, Bundle dict) {
0700:        Element lang_report_elem = xml.createElement("LANGUAGE_REPORT");
0701:        Element locale_elem = xml.createElement("LOCALE");
0702:        locale_elem.setAttribute("LANGUAGE", (dict.language == null ? dict.encoding : dict.language));
0703:        locale_elem.setAttribute("COUNTRY", (dict.country == null ? "" : dict.country));
0704:        locale_elem.setAttribute("VARIANT", (dict.variant == null ? "" : dict.variant));
0705:        Element nls_total_elem = xml.createElement("NLS_TOTAL");
0706:        Text    nls_total_text = xml.createTextNode(String.valueOf(dict.allItems.size()));
0707:        Element untranslated_total_elem = xml.createElement("UNTRANSLATED_TOTAL");
0708:        Element untranslated_elem = xml.createElement("UNTRANSLATED");
0709:        
0710:        nls_total_elem.appendChild(nls_total_text);
0711:        lang_report_elem.appendChild(locale_elem);
0712:        lang_report_elem.appendChild(nls_total_elem);
0713:        lang_report_elem.appendChild(untranslated_total_elem);
0714:        if (detailed) lang_report_elem.appendChild(untranslated_elem);
0715:		
0716:        int untranslated = 0;
0717:        Enumeration enum = dict.allItems.elements();
0718:        while (enum.hasMoreElements()) {
0719:            BundleItem tempItem = (BundleItem)enum.nextElement();
0720:            if (tempItem.isTranslated()) continue;
0721:            untranslated++;
0722:            Element resource_elem = xml.createElement("RESOURCEKEY");
0723:            Text    resource_text = xml.createTextNode(tempItem.getKey());
0724:            resource_elem.appendChild(resource_text);
0725:            untranslated_elem.appendChild(resource_elem);
0726:        }
0727:        Text untranslated_total_text = xml.createTextNode(String.valueOf(untranslated));
0728:        untranslated_total_elem.appendChild(untranslated_total_text);
0729:		
0730:        return lang_report_elem;
0731:    }
0732:
0733:            private String getXMLLanguageReport(boolean detailed, Bundle dict) {
0734:        StringBuffer buffer = new StringBuffer();
0735:        buffer.append("<LANGUAGE_REPORT>\n");
0736:        
0737:        buffer.append("\n\t<LOCALE LANGUAGE=\"" + (dict.language == null ? dict.encoding : dict.language));
0738:        buffer.append("\" COUNTRY=\"" + (dict.country == null ? "" : dict.country));
0739:        buffer.append("\" VARIANT=\"" + (dict.variant == null ? "" : dict.variant) + "\"/>\n");
0740:		
0741:        buffer.append("\t<NLS_TOTAL>" + String.valueOf(dict.allItems.size()) + "</NLS_TOTAL>\n");
0742:        int untranslated = 0;
0743:        Enumeration enum = dict.allItems.elements();
0744:        StringBuffer innerBuffer = new StringBuffer();
0745:        while (enum.hasMoreElements()) {
0746:            BundleItem tempItem = (BundleItem)enum.nextElement();
0747:            if (tempItem.isTranslated()) continue;
0748:            untranslated++;
0749:            innerBuffer.append("\t\t<RESOURCEKEY>" + tempItem.getKey() + "</RESOURCEKEY>\n");
0750:        }
0751:        buffer.append("\t<UNTRANSLATED_TOTAL>" + String.valueOf(untranslated) + "</UNTRANSLATED_TOTAL>\n");
0752:        if (detailed) {
0753:            buffer.append("\t<UNTRANSLATED>\n");
0754:            buffer.append(innerBuffer.toString());
0755:            buffer.append("\t</UNTRANSLATED>\n");
0756:        }
0757:		
0758:        buffer.append("</LANGUAGE_REPORT>\n");
0759:        return buffer.toString();
0760:    }
0761:
0762:            private void updateDateFields() {
0763:                if (nextReport == null)
0764:                    nextReportLabel.setText(Resources.getTranslation(
0765:                            "reporter_next_report", "--"));
0766:                else
0767:                    nextReportLabel.setText(Resources.getTranslation(
0768:                            "reporter_next_report", nextReport.toString()));
0769:                if (lastReport == null)
0770:                    lastReportLabel.setText(Resources.getTranslation(
0771:                            "reporter_last_report", "--"));
0772:                else
0773:                    lastReportLabel.setText(Resources.getTranslation(
0774:                            "reporter_last_report", lastReport.toString()));
0775:            }
0776:
0777:            private void updateStatusComponents() {
0778:                if (running) {
0779:                    statusLabel.setText(Resources
0780:                            .getTranslation("reporter_status_running"));
0781:                    statusLabel.setForeground(Color.green);
0782:                    statusButton.setText(Resources
0783:                            .getTranslation("reporter_button_stop"));
0784:                } else {
0785:                    statusLabel.setText(Resources
0786:                            .getTranslation("reporter_status_stopped"));
0787:                    statusLabel.setForeground(Color.red);
0788:                    statusButton.setText(Resources
0789:                            .getTranslation("reporter_button_start"));
0790:                }
0791:            }
0792:
0793:            private void setComponentsToDefaults() {
0794:                if ((running && Preferences.getPreference("reporter_enabled")
0795:                        .equals("No"))
0796:                        || (!running && Preferences.getPreference(
0797:                                "reporter_enabled").equals("Yes")))
0798:                    toggleStatus();
0799:                if (Preferences.getPreference("reporter_format_text_enabled") != null)
0800:                    textCheck.setSelected(Preferences.getPreference(
0801:                            "reporter_format_text_enabled").equals("Yes"));
0802:                if (Preferences.getPreference("reporter_format_html_enabled") != null)
0803:                    htmlCheck.setSelected(Preferences.getPreference(
0804:                            "reporter_format_html_enabled").equals("Yes"));
0805:                if (Preferences.getPreference("reporter_format_xml_enabled") != null)
0806:                    xmlCheck.setSelected(Preferences.getPreference(
0807:                            "reporter_format_xml_enabled").equals("Yes"));
0808:                if (Preferences.getPreference("reporter_format_text_file") != null
0809:                        && !Preferences.getPreference(
0810:                                "reporter_format_text_file").equals(""))
0811:                    textField.setText(Preferences
0812:                            .getPreference("reporter_format_text_file"));
0813:                if (Preferences.getPreference("reporter_format_html_file") != null
0814:                        && !Preferences.getPreference(
0815:                                "reporter_format_html_file").equals(""))
0816:                    htmlField.setText(Preferences
0817:                            .getPreference("reporter_format_html_file"));
0818:                if (Preferences.getPreference("reporter_format_xml_file") != null
0819:                        && !Preferences.getPreference(
0820:                                "reporter_format_xml_file").equals(""))
0821:                    xmlField.setText(Preferences
0822:                            .getPreference("reporter_format_xml_file"));
0823:                if (Preferences.getPreference("reporter_format_text_detail") != null
0824:                        && !Preferences.getPreference(
0825:                                "reporter_format_text_detail").equals(""))
0826:                    selectComboValue(textCombo, Preferences
0827:                            .getPreference("reporter_format_text_detail"));
0828:                if (Preferences.getPreference("reporter_format_html_detail") != null
0829:                        && !Preferences.getPreference(
0830:                                "reporter_format_html_detail").equals(""))
0831:                    selectComboValue(htmlCombo, Preferences
0832:                            .getPreference("reporter_format_html_detail"));
0833:                if (Preferences.getPreference("reporter_format_xml_detail") != null
0834:                        && !Preferences.getPreference(
0835:                                "reporter_format_xml_detail").equals(""))
0836:                    selectComboValue(xmlCombo, Preferences
0837:                            .getPreference("reporter_format_xml_detail"));
0838:                if (Preferences.getPreference("reporter_interval").equals(
0839:                        "Sequential"))
0840:                    sequentialRadio.setSelected(true);
0841:                else
0842:                    definedRadio.setSelected(true);
0843:                if (Preferences
0844:                        .getPreference("reporter_interval_sequential_value") != null
0845:                        && !Preferences.getPreference(
0846:                                "reporter_interval_sequential_value")
0847:                                .equals(""))
0848:                    selectComboValue(
0849:                            valueCombo,
0850:                            Preferences
0851:                                    .getPreference("reporter_interval_sequential_value"));
0852:                if (Preferences
0853:                        .getPreference("reporter_interval_sequential_units") != null
0854:                        && !Preferences.getPreference(
0855:                                "reporter_interval_sequential_units")
0856:                                .equals(""))
0857:                    selectComboValue(
0858:                            valueCombo,
0859:                            Preferences
0860:                                    .getPreference("reporter_interval_sequential_units"));
0861:                if (Preferences.getPreference("reporter_interval_defined_hour") != null
0862:                        && !Preferences.getPreference(
0863:                                "reporter_interval_defined_hour").equals(""))
0864:                    selectComboValue(hourCombo, Preferences
0865:                            .getPreference("reporter_interval_defined_hour"));
0866:                if (Preferences.getPreference("reporter_interval_defined_day") != null
0867:                        && !Preferences.getPreference(
0868:                                "reporter_interval_defined_day").equals(""))
0869:                    selectComboValue(dayCombo, Preferences
0870:                            .getPreference("reporter_interval_defined_day"));
0871:                if (Preferences
0872:                        .getPreference("reporter_interval_defined_minute") != null
0873:                        && !Preferences.getPreference(
0874:                                "reporter_interval_defined_minute").equals(""))
0875:                    selectComboValue(minuteCombo, Preferences
0876:                            .getPreference("reporter_interval_defined_minute"));
0877:                if (Preferences.getPreference("reporter_scan_file") != null
0878:                        && !Preferences.getPreference("reporter_scan_file")
0879:                                .equals(""))
0880:                    scanField.setText(Preferences
0881:                            .getPreference("reporter_scan_file"));
0882:                if (Preferences.getPreference("reporter_perform_scan") != null)
0883:                    scanCheck.setSelected(Preferences.getPreference(
0884:                            "reporter_perform_scan").equals("Yes"));
0885:            }
0886:
0887:            private static void selectComboValue(JComboBox box, String value) {
0888:                for (int i = 0; i < box.getItemCount(); i++) {
0889:                    if (box.getItemAt(i).toString().equals(value)) {
0890:                        box.setSelectedIndex(i);
0891:                        break;
0892:                    }
0893:                }
0894:            }
0895:
0896:            private void saveDefaults() {
0897:                // Save format options
0898:                Preferences.setPreference("reporter_format_text_enabled",
0899:                        (textCheck.isSelected() ? "Yes" : "No"));
0900:                Preferences.setPreference("reporter_format_text_file",
0901:                        textField.getText());
0902:                Preferences.setPreference("reporter_format_text_detail",
0903:                        textCombo.getSelectedItem().toString());
0904:                Preferences.setPreference("reporter_format_html_enabled",
0905:                        (htmlCheck.isSelected() ? "Yes" : "No"));
0906:                Preferences.setPreference("reporter_format_html_file",
0907:                        htmlField.getText());
0908:                Preferences.setPreference("reporter_format_html_detail",
0909:                        htmlCombo.getSelectedItem().toString());
0910:                Preferences.setPreference("reporter_format_xml_enabled",
0911:                        (xmlCheck.isSelected() ? "Yes" : "No"));
0912:                Preferences.setPreference("reporter_format_xml_file", xmlField
0913:                        .getText());
0914:                Preferences.setPreference("reporter_format_xml_detail",
0915:                        xmlCombo.getSelectedItem().toString());
0916:                Preferences.setPreference("reporter_scan_file", scanField
0917:                        .getText());
0918:                Preferences.setPreference("reporter_perform_scan", (scanCheck
0919:                        .isSelected() ? "Yes" : "No"));
0920:                // Save interval options
0921:                Preferences.setPreference("reporter_interval", (sequentialRadio
0922:                        .isSelected() ? "Sequential" : "Defined"));
0923:                Preferences.setPreference("reporter_interval_sequential_value",
0924:                        valueCombo.getSelectedItem().toString());
0925:                Preferences.setPreference("reporter_interval_sequential_units",
0926:                        unitCombo.getSelectedItem().toString());
0927:                Preferences.setPreference("reporter_interval_defined_hour",
0928:                        hourCombo.getSelectedItem().toString());
0929:                Preferences.setPreference("reporter_interval_defined_minute",
0930:                        minuteCombo.getSelectedItem().toString());
0931:                Preferences.setPreference("reporter_interval_defined_day",
0932:                        dayCombo.getSelectedItem().toString());
0933:                // Save system options
0934:                Preferences.setPreference("reporter_enabled", (running ? "Yes"
0935:                        : "No"));
0936:                // Write the preferences
0937:                try {
0938:                    Preferences.savePreferences();
0939:                } catch (IOException ioe) {
0940:                    // TODO: Warn of error through JOptionPane
0941:                    ioe.printStackTrace();
0942:                }
0943:            }
0944:
0945:            private void toggleStatus() {
0946:                if (running) {
0947:                    running = false;
0948:                } else {
0949:                    running = true;
0950:                }
0951:                updateStatusComponents();
0952:            }
0953:
0954:            private void initComponents() {
0955:
0956:                // File choosers
0957:                bundleFileChooser
0958:                        .setFileFilter(new javax.swing.filechooser.FileFilter() {
0959:                            public boolean accept(File f) {
0960:                                if (f.isDirectory())
0961:                                    return true;
0962:
0963:                                String name = f.getName();
0964:                                if (!(name.toLowerCase()
0965:                                        .endsWith(".properties")))
0966:                                    return false;
0967:                                if (name.indexOf("_") > 0)
0968:                                    return false;
0969:                                return true;
0970:                            }
0971:
0972:                            public String getDescription() {
0973:                                return Resources
0974:                                        .getTranslation("dialog_file_filter_description");
0975:                            }
0976:                        });
0977:                bundleFileChooser.setSelectedFile(new File(Preferences
0978:                        .getPreference("reporter_base_class_file")));
0979:
0980:                directoryFileChooser
0981:                        .setFileFilter(new javax.swing.filechooser.FileFilter() {
0982:                            public boolean accept(File f) {
0983:                                if (f.isDirectory())
0984:                                    return true;
0985:                                return false;
0986:                            }
0987:
0988:                            public String getDescription() {
0989:                                return Resources.getTranslation("directory");
0990:                            }
0991:                        });
0992:                directoryFileChooser.setSelectedFile(new File(Preferences
0993:                        .getPreference("reporter_output_directory")));
0994:
0995:                scanFileChooser
0996:                        .setFileFilter(new javax.swing.filechooser.FileFilter() {
0997:                            public boolean accept(File f) {
0998:                                if (f.isDirectory())
0999:                                    return true;
1000:                                if (f.getName().endsWith(".xml"))
1001:                                    return true;
1002:                                return false;
1003:                            }
1004:
1005:                            public String getDescription() {
1006:                                return Resources
1007:                                        .getTranslation("dialog_file_filter_description_scan");
1008:                            }
1009:                        });
1010:                scanFileChooser.setSelectedFile(new File(Preferences
1011:                        .getPreference("reporter_scan_file")));
1012:
1013:                // New top level components
1014:                JPanel statusPanel = new JPanel();
1015:                JPanel intervalPanel = new JPanel();
1016:                JPanel optionsPanel = new JPanel();
1017:                JPanel formatPanel = new JPanel();
1018:                Box mainBox = new Box(BoxLayout.Y_AXIS);
1019:                int width = 600;
1020:                int height = 600;
1021:                int compHeight = 20;
1022:                Dimension mainDim = new Dimension(width, height);
1023:
1024:                statusPanel.setBorder(BorderFactory.createTitledBorder(
1025:                        BorderFactory.createEtchedBorder(), Resources
1026:                                .getTranslation("reporter_panel_status")));
1027:                intervalPanel.setBorder(BorderFactory.createTitledBorder(
1028:                        BorderFactory.createEtchedBorder(), Resources
1029:                                .getTranslation("reporter_panel_interval")));
1030:                optionsPanel.setBorder(BorderFactory.createTitledBorder(
1031:                        BorderFactory.createEtchedBorder(), Resources
1032:                                .getTranslation("reporter_panel_options")));
1033:                formatPanel
1034:                        .setBorder(BorderFactory
1035:                                .createTitledBorder(
1036:                                        BorderFactory.createEtchedBorder(),
1037:                                        Resources
1038:                                                .getTranslation("reporter_panel_output_format")));
1039:
1040:                // ** STATUS PANEL SETUP **
1041:                JButton nowButton = new JButton(Resources
1042:                        .getTranslation("reporter_button_now"));
1043:                Box statusBox = new Box(BoxLayout.Y_AXIS);
1044:                JPanel statusPanel1 = new JPanel();
1045:                JPanel statusPanel2 = new JPanel();
1046:                JPanel statusPanel3 = new JPanel();
1047:                JPanel statusPanel4 = new JPanel();
1048:                statusButton = new JButton(Resources
1049:                        .getTranslation("reporter_button_start"));
1050:                statusLabel = new JLabel(Resources
1051:                        .getTranslation("reporter_status_stopped"));
1052:                nextReportLabel = new JLabel(Resources.getTranslation(
1053:                        "reporter_next_report", "--"));
1054:                lastReportLabel = new JLabel(Resources.getTranslation(
1055:                        "reporter_last_report", "--"));
1056:                statusLabel.setFont(new Font("serif", Font.BOLD, 14));
1057:                statusLabel.setForeground(Color.red);
1058:                statusPanel2.setLayout(new FlowLayout(FlowLayout.LEFT));
1059:                statusPanel3.setLayout(new FlowLayout(FlowLayout.LEFT));
1060:                statusPanel.setLayout(new BorderLayout());
1061:
1062:                nowButton.addActionListener(new ActionListener() {
1063:                    public void actionPerformed(ActionEvent ev) {
1064:                        try {
1065:                            generateReports();
1066:                        } catch (Exception e) {
1067:                            JOptionPane.showMessageDialog(null, e.getMessage(),
1068:                                    Resources.getTranslation("error"),
1069:                                    JOptionPane.ERROR_MESSAGE);
1070:                            RBManagerGUI.debugMsg(e.toString());
1071:                            if (RBManagerGUI.debug)
1072:                                e.printStackTrace(System.err);
1073:                        }
1074:                    }
1075:                });
1076:
1077:                statusButton.addActionListener(new ActionListener() {
1078:                    public void actionPerformed(ActionEvent ev) {
1079:                        toggleStatus();
1080:                    }
1081:                });
1082:
1083:                statusPanel1.add(statusLabel);
1084:                statusPanel2.add(nextReportLabel);
1085:                statusPanel3.add(lastReportLabel);
1086:                statusPanel4.add(nowButton);
1087:                statusPanel4.add(Box.createHorizontalStrut(7));
1088:                statusPanel4.add(statusButton);
1089:                statusBox.add(statusPanel1);
1090:                statusBox.add(Box.createVerticalStrut(7));
1091:                //statusBox.add(Box.createHorizontalGlue());
1092:                statusBox.add(statusPanel2);
1093:                //statusBox.add(Box.createHorizontalGlue());
1094:                statusBox.add(statusPanel3);
1095:                statusBox.add(Box.createVerticalStrut(7));
1096:                statusBox.add(statusPanel4);
1097:                statusPanel.add(statusBox, BorderLayout.CENTER);
1098:
1099:                // ** OPTIONS PANEL SETUP **
1100:                JLabel inputLabel = new JLabel(Resources
1101:                        .getTranslation("reporter_input_bundle"));
1102:                JLabel outputLabel = new JLabel(Resources
1103:                        .getTranslation("reporter_output_directory"));
1104:                JButton inputButton = new JButton(Resources
1105:                        .getTranslation("reporter_button_choose"));
1106:                JButton outputButton = new JButton(Resources
1107:                        .getTranslation("reporter_button_choose"));
1108:                JButton scanButton = new JButton(Resources
1109:                        .getTranslation("reporter_button_choose"));
1110:                JButton defaultButton = new JButton(Resources
1111:                        .getTranslation("reporter_button_save_defaults"));
1112:                JLabel textLabel = new JLabel(Resources
1113:                        .getTranslation("reporter_output_file"));
1114:                JLabel htmlLabel = new JLabel(Resources
1115:                        .getTranslation("reporter_output_file"));
1116:                JLabel xmlLabel = new JLabel(Resources
1117:                        .getTranslation("reporter_output_file"));
1118:                JLabel textLabel2 = new JLabel(Resources
1119:                        .getTranslation("reporter_detail_level"));
1120:                JLabel htmlLabel2 = new JLabel(Resources
1121:                        .getTranslation("reporter_detail_level"));
1122:                JLabel xmlLabel2 = new JLabel(Resources
1123:                        .getTranslation("reporter_detail_level"));
1124:                JPanel optionsPanel1 = new JPanel();
1125:                JPanel optionsPanel2 = new JPanel();
1126:                JPanel optionsPanelA = new JPanel();
1127:                JPanel optionsPanel3 = new JPanel();
1128:                JPanel optionsPanel4 = new JPanel();
1129:                JPanel optionsPanel5 = new JPanel();
1130:                JPanel optionsPanel6 = new JPanel();
1131:                Box optionsBox = new Box(BoxLayout.Y_AXIS);
1132:                Box outputBox = new Box(BoxLayout.Y_AXIS);
1133:
1134:                bundleField = new JTextField(Preferences
1135:                        .getPreference("reporter_base_class_file"));
1136:                directoryField = new JTextField(Preferences
1137:                        .getPreference("reporter_output_directory"));
1138:                textCheck = new JCheckBox(Resources
1139:                        .getTranslation("reporter_format_text"));
1140:                htmlCheck = new JCheckBox(Resources
1141:                        .getTranslation("reporter_format_html"));
1142:                xmlCheck = new JCheckBox(Resources
1143:                        .getTranslation("reporter_format_xml"));
1144:                scanCheck = new JCheckBox(Resources
1145:                        .getTranslation("reporter_perform_scan"), false);
1146:                textField = new JTextField("report.txt");
1147:                htmlField = new JTextField("report.html");
1148:                xmlField = new JTextField("report.xml");
1149:                scanField = new JTextField();
1150:                String[] detailLevels = {
1151:                        Resources.getTranslation("reporter_detail_high"),
1152:                        Resources.getTranslation("reporter_detail_normal") };
1153:                textCombo = new JComboBox(detailLevels);
1154:                htmlCombo = new JComboBox(detailLevels);
1155:                xmlCombo = new JComboBox(detailLevels);
1156:
1157:                bundleField.setColumns(30);
1158:                directoryField.setColumns(30);
1159:                scanField.setColumns(30);
1160:                textField.setColumns(15);
1161:                htmlField.setColumns(15);
1162:                xmlField.setColumns(15);
1163:                Dimension checkDim = new Dimension(55, compHeight);
1164:                textCheck.setPreferredSize(checkDim);
1165:                htmlCheck.setPreferredSize(checkDim);
1166:                xmlCheck.setPreferredSize(checkDim);
1167:                optionsPanel1.setLayout(new FlowLayout(FlowLayout.RIGHT));
1168:                optionsPanel2.setLayout(new FlowLayout(FlowLayout.RIGHT));
1169:                optionsPanelA.setLayout(new FlowLayout(FlowLayout.RIGHT));
1170:
1171:                inputButton.addActionListener(new ActionListener() {
1172:                    public void actionPerformed(ActionEvent ev) {
1173:                        setInputBundle();
1174:                    }
1175:                });
1176:
1177:                outputButton.addActionListener(new ActionListener() {
1178:                    public void actionPerformed(ActionEvent ev) {
1179:                        setOutputBundle();
1180:                    }
1181:                });
1182:
1183:                scanButton.addActionListener(new ActionListener() {
1184:                    public void actionPerformed(ActionEvent ev) {
1185:                        setScanFile();
1186:                    }
1187:                });
1188:
1189:                defaultButton.addActionListener(new ActionListener() {
1190:                    public void actionPerformed(ActionEvent ev) {
1191:                        saveDefaults();
1192:                    }
1193:                });
1194:
1195:                optionsPanel6.add(defaultButton);
1196:                optionsPanel3.add(textCheck);
1197:                optionsPanel3.add(Box.createHorizontalStrut(5));
1198:                optionsPanel3.add(textLabel);
1199:                optionsPanel3.add(Box.createHorizontalStrut(5));
1200:                optionsPanel3.add(textField);
1201:                optionsPanel3.add(Box.createHorizontalStrut(5));
1202:                optionsPanel3.add(textLabel2);
1203:                optionsPanel3.add(Box.createHorizontalStrut(5));
1204:                optionsPanel3.add(textCombo);
1205:                optionsPanel4.add(htmlCheck);
1206:                optionsPanel4.add(Box.createHorizontalStrut(5));
1207:                optionsPanel4.add(htmlLabel);
1208:                optionsPanel4.add(Box.createHorizontalStrut(5));
1209:                optionsPanel4.add(htmlField);
1210:                optionsPanel4.add(Box.createHorizontalStrut(5));
1211:                optionsPanel4.add(htmlLabel2);
1212:                optionsPanel4.add(Box.createHorizontalStrut(5));
1213:                optionsPanel4.add(htmlCombo);
1214:                optionsPanel5.add(xmlCheck);
1215:                optionsPanel5.add(Box.createHorizontalStrut(5));
1216:                optionsPanel5.add(xmlLabel);
1217:                optionsPanel5.add(Box.createHorizontalStrut(5));
1218:                optionsPanel5.add(xmlField);
1219:                optionsPanel5.add(Box.createHorizontalStrut(5));
1220:                optionsPanel5.add(xmlLabel2);
1221:                optionsPanel5.add(Box.createHorizontalStrut(5));
1222:                optionsPanel5.add(xmlCombo);
1223:                outputBox.add(optionsPanel3);
1224:                outputBox.add(optionsPanel4);
1225:                outputBox.add(optionsPanel5);
1226:                formatPanel.add(outputBox);
1227:                optionsPanel1.add(inputLabel);
1228:                optionsPanel1.add(Box.createHorizontalStrut(5));
1229:                optionsPanel1.add(bundleField);
1230:                optionsPanel1.add(Box.createHorizontalStrut(5));
1231:                optionsPanel1.add(inputButton);
1232:                optionsPanel2.add(outputLabel);
1233:                optionsPanel2.add(Box.createHorizontalStrut(5));
1234:                optionsPanel2.add(directoryField);
1235:                optionsPanel2.add(Box.createHorizontalStrut(5));
1236:                optionsPanel2.add(outputButton);
1237:                optionsPanelA.add(scanCheck);
1238:                optionsPanelA.add(Box.createHorizontalStrut(5));
1239:                optionsPanelA.add(scanField);
1240:                optionsPanelA.add(Box.createHorizontalStrut(5));
1241:                optionsPanelA.add(scanButton);
1242:                optionsBox.add(optionsPanel1);
1243:                optionsBox.add(optionsPanel2);
1244:                optionsBox.add(optionsPanelA);
1245:                optionsBox.add(formatPanel);
1246:                optionsBox.add(optionsPanel6);
1247:                optionsPanel.add(optionsBox);
1248:
1249:                // ** INTERVAL PANEL SETUP **
1250:                String boxArray1[] = { "1", "2", "3", "4", "5", "6", "7", "8",
1251:                        "9", "10", "11", "12", "15", "20", "24", "25", "30" };
1252:                String boxArray2[] = {
1253:                        Resources.getTranslation("reporter_time_minutes"),
1254:                        Resources.getTranslation("reporter_time_hours"),
1255:                        Resources.getTranslation("reporter_time_days") };
1256:                String boxArray3[] = { "1", "2", "3", "4", "5", "6", "7", "8",
1257:                        "9", "10", "11", "12", "13", "14", "15", "16", "17",
1258:                        "18", "19", "20", "21", "22", "23", "0" };
1259:                String boxArray4[] = { "00", "15", "30", "45" };
1260:                String boxArray5[] = {
1261:                        Resources.getTranslation("reporter_time_everyday"),
1262:                        Resources.getTranslation("reporter_time_monday"),
1263:                        Resources.getTranslation("reporter_time_tuesday"),
1264:                        Resources.getTranslation("reporter_time_wednesday"),
1265:                        Resources.getTranslation("reporter_time_thursday"),
1266:                        Resources.getTranslation("reporter_time_friday"),
1267:                        Resources.getTranslation("reporter_time_saturday"),
1268:                        Resources.getTranslation("reporter_time_sunday") };
1269:
1270:                JLabel colonLabel = new JLabel(":");
1271:                sequentialRadio = new JRadioButton(Resources
1272:                        .getTranslation("reporter_interval_sequential"));
1273:                definedRadio = new JRadioButton(Resources
1274:                        .getTranslation("reporter_interval_defined"), true);
1275:                valueCombo = new JComboBox(boxArray1);
1276:                unitCombo = new JComboBox(boxArray2);
1277:                hourCombo = new JComboBox(boxArray3);
1278:                minuteCombo = new JComboBox(boxArray4);
1279:                dayCombo = new JComboBox(boxArray5);
1280:                JPanel intervalPanel1 = new JPanel();
1281:                JPanel intervalPanel2 = new JPanel();
1282:                intervalPanel1.setLayout(new FlowLayout(FlowLayout.LEFT));
1283:                intervalPanel2.setLayout(new FlowLayout(FlowLayout.LEFT));
1284:                Box intervalBox = new Box(BoxLayout.Y_AXIS);
1285:                intervalPanel.setLayout(new BorderLayout());
1286:
1287:                ButtonGroup bg = new ButtonGroup();
1288:                bg.add(sequentialRadio);
1289:                bg.add(definedRadio);
1290:
1291:                intervalPanel1.add(sequentialRadio);
1292:                intervalPanel1.add(Box.createHorizontalStrut(5));
1293:                intervalPanel1.add(valueCombo);
1294:                intervalPanel1.add(Box.createHorizontalStrut(5));
1295:                intervalPanel1.add(unitCombo);
1296:                intervalPanel2.add(definedRadio);
1297:                intervalPanel2.add(Box.createHorizontalStrut(5));
1298:                intervalPanel2.add(hourCombo);
1299:                intervalPanel2.add(colonLabel);
1300:                intervalPanel2.add(minuteCombo);
1301:                intervalPanel2.add(Box.createHorizontalStrut(5));
1302:                intervalPanel2.add(dayCombo);
1303:                intervalBox.add(intervalPanel1);
1304:                intervalBox.add(intervalPanel2);
1305:                intervalPanel.add(intervalBox, BorderLayout.WEST);
1306:
1307:                // ** MAINBOX SETUP **
1308:                mainBox.removeAll();
1309:                mainBox.add(statusPanel);
1310:                mainBox.add(intervalPanel);
1311:                mainBox.add(optionsPanel);
1312:
1313:                // ** MAIN FRAME SETUP **
1314:                setLocation(new java.awt.Point(25, 25));
1315:                setSize(mainDim);
1316:                //((JComponent)getContentPane()).setMaximumSize(dimMainMax);
1317:                //((JComponent)getContentPane()).setMinimumSize(dimMainMin);
1318:                //setJMenuBar(jMenuBarMain);
1319:                getContentPane().setLayout(new BorderLayout());
1320:                getContentPane().removeAll();
1321:                getContentPane().add(mainBox, BorderLayout.CENTER);
1322:                setTitle(Resources.getTranslation("resource_bundle_reporter"));
1323:                //validateTree();
1324:                setComponentsToDefaults();
1325:                nextReport = generateNextReportDate();
1326:                updateDateFields();
1327:                repaint();
1328:
1329:                addWindowListener(new java.awt.event.WindowAdapter() {
1330:                    public void windowClosing(java.awt.event.WindowEvent ev) {
1331:                        this WindowClosing(ev);
1332:                    }
1333:                });
1334:            }
1335:
1336:            public void this WindowClosing(WindowEvent ev) {
1337:                setVisible(false);
1338:                dispose();
1339:                System.exit(0);
1340:            }
1341:
1342:            private void setInputBundle() {
1343:                int result = bundleFileChooser.showOpenDialog(this );
1344:                if (result == JFileChooser.APPROVE_OPTION) {
1345:                    File f = bundleFileChooser.getSelectedFile();
1346:                    if (f != null) {
1347:                        bundleField.setText(f.getAbsolutePath());
1348:                        Preferences.setPreference("reporter_base_class_file", f
1349:                                .getAbsolutePath());
1350:                        try {
1351:                            Preferences.savePreferences();
1352:                        } catch (IOException ioe) {
1353:                        }
1354:                    }
1355:                }
1356:            }
1357:
1358:            private void setOutputBundle() {
1359:                int result = directoryFileChooser.showOpenDialog(this );
1360:                if (result == JFileChooser.APPROVE_OPTION) {
1361:                    File f = directoryFileChooser.getSelectedFile();
1362:                    if (!f.isDirectory())
1363:                        f = new File(f.getParent());
1364:                    if (f != null) {
1365:                        directoryField.setText(f.getAbsolutePath());
1366:                        Preferences.setPreference("reporter_output_directory",
1367:                                f.getAbsolutePath());
1368:                        try {
1369:                            Preferences.savePreferences();
1370:                        } catch (IOException ioe) {
1371:                        }
1372:                    }
1373:                }
1374:            }
1375:
1376:            private void setScanFile() {
1377:                int result = scanFileChooser.showOpenDialog(this );
1378:                if (result == JFileChooser.APPROVE_OPTION) {
1379:                    File f = scanFileChooser.getSelectedFile();
1380:                    if (f != null) {
1381:                        scanField.setText(f.getAbsolutePath());
1382:                        Preferences.setPreference("reporter_scan_file", f
1383:                                .getAbsolutePath());
1384:                        try {
1385:                            Preferences.savePreferences();
1386:                        } catch (IOException ioe) {
1387:                        }
1388:                    }
1389:                }
1390:            }
1391:
1392:            private static String getUsage() {
1393:                return "\nRBReporter Command Line Usage:\n\n"
1394:                        + "Default Usage (GUI):   java com.ibm.rbm.RBReporter\n"
1395:                        + "Options Usage:         java com.ibm.rbm.RBReporter [-gui | -now | -line]\n\n"
1396:                        + "Options:               -gui     Run the Graphical User Interface\n"
1397:                        + "                       -now     Execute the Report Generation Immediately\n"
1398:                        + "                       -line    Run the Reporter without the GUI";
1399:            }
1400:
1401:            public static void main(String args[]) {
1402:                RBReporter reporter;
1403:                if (args.length == 1) {
1404:                    if (args[0].equals("-gui")) {
1405:                        reporter = new RBReporter(true);
1406:                    } else if (args[0].equals("-now")) {
1407:                        reporter = new RBReporter(false);
1408:                        try {
1409:                            reporter.generateReports();
1410:                            System.out
1411:                                    .println("RBReporter: Generation of reports successful. "
1412:                                            + new Date());
1413:                        } catch (IOException ioe) {
1414:                            System.out
1415:                                    .println("There was an error generating the reports...\n\n\t"
1416:                                            + ioe.getMessage());
1417:                        }
1418:                        reporter.this WindowClosing(null);
1419:                    } else if (args[0].equals("-line")) {
1420:                        reporter = new RBReporter(false);
1421:                        if (!reporter.running)
1422:                            reporter.toggleStatus();
1423:                        System.out.println("RBReporter: Next Report at "
1424:                                + reporter.nextReport.toString());
1425:                    } else {
1426:                        System.out.println(getUsage());
1427:                    }
1428:                } else if (args.length == 0) {
1429:                    reporter = new RBReporter(true);
1430:                } else {
1431:                    System.out.println(getUsage());
1432:                }
1433:            }
1434:
1435:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.