Source Code Cross Referenced for PlainTextExportDialog.java in  » Report » pentaho-report » org » jfree » report » modules » gui » plaintext » 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 » pentaho report » org.jfree.report.modules.gui.plaintext 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * ===========================================
0003:         * JFreeReport : a free Java reporting library
0004:         * ===========================================
0005:         *
0006:         * Project Info:  http://reporting.pentaho.org/
0007:         *
0008:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
0009:         *
0010:         * This library is free software; you can redistribute it and/or modify it under the terms
0011:         * of the GNU Lesser General Public License as published by the Free Software Foundation;
0012:         * either version 2.1 of the License, or (at your option) any later version.
0013:         *
0014:         * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
0015:         * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0016:         * See the GNU Lesser General Public License for more details.
0017:         *
0018:         * You should have received a copy of the GNU Lesser General Public License along with this
0019:         * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
0020:         * Boston, MA 02111-1307, USA.
0021:         *
0022:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
0023:         * in the United States and other countries.]
0024:         *
0025:         * ------------
0026:         * PlainTextExportDialog.java
0027:         * ------------
0028:         * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
0029:         */package org.jfree.report.modules.gui.plaintext;
0030:
0031:        import java.awt.BorderLayout;
0032:        import java.awt.Dialog;
0033:        import java.awt.Frame;
0034:        import java.awt.GridBagConstraints;
0035:        import java.awt.GridBagLayout;
0036:        import java.awt.Insets;
0037:        import java.awt.event.ActionEvent;
0038:        import java.io.File;
0039:        import java.text.MessageFormat;
0040:        import java.util.Arrays;
0041:        import java.util.Locale;
0042:        import java.util.ResourceBundle;
0043:        import javax.swing.AbstractAction;
0044:        import javax.swing.Action;
0045:        import javax.swing.BorderFactory;
0046:        import javax.swing.ButtonGroup;
0047:        import javax.swing.ComboBoxModel;
0048:        import javax.swing.DefaultComboBoxModel;
0049:        import javax.swing.JButton;
0050:        import javax.swing.JComboBox;
0051:        import javax.swing.JComponent;
0052:        import javax.swing.JFileChooser;
0053:        import javax.swing.JLabel;
0054:        import javax.swing.JOptionPane;
0055:        import javax.swing.JPanel;
0056:        import javax.swing.JRadioButton;
0057:        import javax.swing.JTabbedPane;
0058:        import javax.swing.JTextField;
0059:
0060:        import org.jfree.fonts.encoding.EncodingRegistry;
0061:        import org.jfree.report.JFreeReportBoot;
0062:        import org.jfree.report.modules.gui.commonswing.AbstractExportDialog;
0063:        import org.jfree.report.modules.gui.commonswing.JStatusBar;
0064:        import org.jfree.report.modules.gui.commonswing.StatusType;
0065:        import org.jfree.report.modules.output.pageable.plaintext.PlainTextPageableModule;
0066:        import org.jfree.report.modules.output.pageable.plaintext.driver.Epson24PinPrinterDriver;
0067:        import org.jfree.report.modules.output.pageable.plaintext.driver.Epson9PinPrinterDriver;
0068:        import org.jfree.report.modules.output.pageable.plaintext.driver.IBMCompatiblePrinterDriver;
0069:        import org.jfree.report.modules.output.pageable.plaintext.helper.PrinterSpecification;
0070:        import org.jfree.report.modules.output.pageable.plaintext.helper.PrinterSpecificationManager;
0071:        import org.jfree.report.util.StringUtil;
0072:        import org.jfree.report.util.i18n.Messages;
0073:        import org.jfree.ui.KeyedComboBoxModel;
0074:        import org.jfree.ui.action.AbstractFileSelectionAction;
0075:        import org.jfree.ui.action.ActionButton;
0076:        import org.jfree.ui.action.ActionRadioButton;
0077:        import org.jfree.util.Configuration;
0078:        import org.jfree.util.DefaultConfiguration;
0079:
0080:        /**
0081:         * A dialog that is used to export reports to plain text.
0082:         *
0083:         * @author Thomas Morgner.
0084:         */
0085:        public class PlainTextExportDialog extends AbstractExportDialog {
0086:            private Messages messages;
0087:
0088:            /**
0089:             * An action to select a file.
0090:             */
0091:            private class ActionSelectFile extends AbstractFileSelectionAction {
0092:                private final ResourceBundle resources;
0093:
0094:                /**
0095:                 * Defines an <code>Action</code> object with a default description string
0096:                 * and default icon.
0097:                 */
0098:                protected ActionSelectFile(final ResourceBundle resources) {
0099:                    super (PlainTextExportDialog.this );
0100:                    this .resources = resources;
0101:                    putValue(Action.NAME, resources
0102:                            .getString("plain-text-exportdialog.selectFile")); //$NON-NLS-1$
0103:                }
0104:
0105:                /**
0106:                 * Returns a descriptive text describing the file extension.
0107:                 *
0108:                 * @return the file description.
0109:                 */
0110:                protected String getFileDescription() {
0111:                    return resources
0112:                            .getString("plain-text-exportdialog.fileDescription"); //$NON-NLS-1$
0113:                }
0114:
0115:                /**
0116:                 * Returns the file extension that should be used for the operation.
0117:                 *
0118:                 * @return the file extension.
0119:                 */
0120:                protected String getFileExtension() {
0121:                    return TXT_FILE_EXTENSION;
0122:                }
0123:
0124:                /**
0125:                 * Invoked when an action occurs.
0126:                 *
0127:                 * @param e the action event.
0128:                 */
0129:                public void actionPerformed(final ActionEvent e) {
0130:                    final File selectedFile = performSelectFile(new File(
0131:                            getFilename()), JFileChooser.SAVE_DIALOG, true);
0132:                    if (selectedFile != null) {
0133:                        setFilename(selectedFile.getPath());
0134:                    }
0135:                }
0136:            }
0137:
0138:            /**
0139:             * An action to select a plain printer.
0140:             */
0141:            private class ActionSelectPrinter extends AbstractAction {
0142:                private int printer;
0143:
0144:                /**
0145:                 * Defines an <code>Action</code> object with a default description string
0146:                 * and default icon.
0147:                 */
0148:                protected ActionSelectPrinter(final String printerName,
0149:                        final int printer) {
0150:                    putValue(NAME, printerName);
0151:                    this .printer = printer;
0152:                }
0153:
0154:                /**
0155:                 * Invoked when an action occurs.
0156:                 *
0157:                 * @param e the action event.
0158:                 */
0159:                public void actionPerformed(final ActionEvent e) {
0160:                    setSelectedPrinter(printer);
0161:                }
0162:            }
0163:
0164:            private class SelectEpsonModelAction extends AbstractAction {
0165:                /**
0166:                 * Defines an <code>Action</code> object with a default description string
0167:                 * and default icon.
0168:                 */
0169:                protected SelectEpsonModelAction() {
0170:                }
0171:
0172:                /**
0173:                 * Invoked when an action occurs.
0174:                 */
0175:                public void actionPerformed(final ActionEvent e) {
0176:                    if (getSelectedPrinter() == TYPE_EPSON9_OUTPUT) {
0177:                        updateEpson9Encoding();
0178:                    } else if (getSelectedPrinter() == TYPE_EPSON24_OUTPUT) {
0179:                        updateEpson24Encoding();
0180:                    }
0181:                }
0182:            }
0183:
0184:            private static final String TXT_FILE_EXTENSION = ".txt"; //$NON-NLS-1$
0185:
0186:            /**
0187:             * Plain text output.
0188:             */
0189:            public static final int TYPE_PLAIN_OUTPUT = 0;
0190:
0191:            /**
0192:             * Epson printer output.
0193:             */
0194:            public static final int TYPE_EPSON9_OUTPUT = 1;
0195:
0196:            /**
0197:             * IBM printer output.
0198:             */
0199:            public static final int TYPE_IBM_OUTPUT = 2;
0200:
0201:            /**
0202:             * Epson printer output.
0203:             */
0204:            public static final int TYPE_EPSON24_OUTPUT = 3;
0205:
0206:            private static final String[] PRINTER_NAMES = new String[] {
0207:                    "plain-text-exportdialog.printer.plain", //$NON-NLS-1$
0208:                    "plain-text-exportdialog.printer.epson9", //$NON-NLS-1$
0209:                    "plain-text-exportdialog.printer.ibm", //$NON-NLS-1$
0210:                    "plain-text-exportdialog.printer.epson24", //$NON-NLS-1$
0211:            };
0212:
0213:            /**
0214:             * 6 lines per inch.
0215:             */
0216:            public static final Float LPI_6 = new Float(6);
0217:
0218:            /**
0219:             * 10 lines per inch.
0220:             */
0221:            public static final Float LPI_10 = new Float(10);
0222:
0223:            /**
0224:             * 10 characters per inch.
0225:             */
0226:            public static final Float CPI_10 = new Float(10);
0227:
0228:            /**
0229:             * 12 characters per inch.
0230:             */
0231:            public static final Float CPI_12 = new Float(12);
0232:
0233:            /**
0234:             * 15 characters per inch.
0235:             */
0236:            public static final Float CPI_15 = new Float(15);
0237:
0238:            /**
0239:             * 17 characters per inch.
0240:             */
0241:            public static final Float CPI_17 = new Float(17.14f);
0242:
0243:            /**
0244:             * 20 characters per inch.
0245:             */
0246:            public static final Float CPI_20 = new Float(20);
0247:
0248:            /**
0249:             * A combo-box for selecting the encoding.
0250:             */
0251:            private EncodingSelector encodingSelector;
0252:
0253:            /**
0254:             * A radio button for selecting plain printer commands.
0255:             */
0256:            private JRadioButton rbPlainPrinterCommandSet;
0257:
0258:            /**
0259:             * A radio button for selecting Epson 9-pin printer commands.
0260:             */
0261:            private JRadioButton rbEpson9PrinterCommandSet;
0262:
0263:            /**
0264:             * A radio button for selecting Epson 24-pin printer commands.
0265:             */
0266:            private JRadioButton rbEpson24PrinterCommandSet;
0267:
0268:            /**
0269:             * A radio button for selecting IBM printer commands.
0270:             */
0271:            private JRadioButton rbIBMPrinterCommandSet;
0272:
0273:            /**
0274:             * The filename text field.
0275:             */
0276:            private JTextField txFilename;
0277:
0278:            /**
0279:             * A combo-box for selecting lines per inch.
0280:             */
0281:            private JComboBox cbLinesPerInch;
0282:
0283:            /**
0284:             * A combo-box for selecting characters per inch.
0285:             */
0286:            private JComboBox cbCharsPerInch;
0287:
0288:            private JComboBox cbEpson9PrinterType;
0289:            private JComboBox cbEpson24PrinterType;
0290:
0291:            private KeyedComboBoxModel epson9Printers;
0292:            private KeyedComboBoxModel epson24Printers;
0293:
0294:            private JStatusBar statusBar;
0295:
0296:            /**
0297:             * Creates a non-modal dialog without a title and without a specified Frame
0298:             * owner.  A shared, hidden frame will be set as the owner of the Dialog.
0299:             */
0300:            public PlainTextExportDialog() {
0301:                init();
0302:            }
0303:
0304:            /**
0305:             * Creates a non-modal dialog without a title with the specifed Frame as its
0306:             * owner.
0307:             *
0308:             * @param owner the Frame from which the dialog is displayed
0309:             */
0310:            public PlainTextExportDialog(final Frame owner) {
0311:                super (owner);
0312:                init();
0313:            }
0314:
0315:            /**
0316:             * Creates a non-modal dialog without a title with the specifed Dialog as its
0317:             * owner.
0318:             *
0319:             * @param owner the Dialog from which the dialog is displayed
0320:             */
0321:            public PlainTextExportDialog(final Dialog owner) {
0322:                super (owner);
0323:                init();
0324:            }
0325:
0326:            /**
0327:             * Initialise the dialog.
0328:             */
0329:            private void init() {
0330:                setTitle(getResources().getString(
0331:                        "plain-text-exportdialog.dialogtitle")); //$NON-NLS-1$
0332:                messages = new Messages(
0333:                        PlainTextExportPlugin.BASE_RESOURCE_CLASS);
0334:                epson9Printers = loadEpson9Printers();
0335:                epson24Printers = loadEpson24Printers();
0336:
0337:                cbEpson9PrinterType = new JComboBox(epson9Printers);
0338:                cbEpson9PrinterType
0339:                        .addActionListener(new SelectEpsonModelAction());
0340:
0341:                cbEpson24PrinterType = new JComboBox(epson24Printers);
0342:                cbEpson24PrinterType
0343:                        .addActionListener(new SelectEpsonModelAction());
0344:
0345:                statusBar = new JStatusBar();
0346:
0347:                final Float[] lpiModel = { LPI_6, LPI_10 };
0348:
0349:                final Float[] cpiModel = { CPI_10, CPI_12, CPI_15, CPI_17,
0350:                        CPI_20 };
0351:
0352:                cbLinesPerInch = new JComboBox(new DefaultComboBoxModel(
0353:                        lpiModel));
0354:                cbCharsPerInch = new JComboBox(new DefaultComboBoxModel(
0355:                        cpiModel));
0356:
0357:                final String plainPrinterName = getResources().getString(
0358:                        PRINTER_NAMES[TYPE_PLAIN_OUTPUT]);
0359:                final String epson9PrinterName = getResources().getString(
0360:                        PRINTER_NAMES[TYPE_EPSON9_OUTPUT]);
0361:                final String epson24PrinterName = getResources().getString(
0362:                        PRINTER_NAMES[TYPE_EPSON24_OUTPUT]);
0363:                final String ibmPrinterName = getResources().getString(
0364:                        PRINTER_NAMES[TYPE_IBM_OUTPUT]);
0365:
0366:                rbPlainPrinterCommandSet = new ActionRadioButton(
0367:                        new ActionSelectPrinter(plainPrinterName,
0368:                                TYPE_PLAIN_OUTPUT));
0369:                rbEpson9PrinterCommandSet = new ActionRadioButton(
0370:                        new ActionSelectPrinter(epson9PrinterName,
0371:                                TYPE_EPSON9_OUTPUT));
0372:                rbEpson24PrinterCommandSet = new ActionRadioButton(
0373:                        new ActionSelectPrinter(epson24PrinterName,
0374:                                TYPE_EPSON24_OUTPUT));
0375:                rbIBMPrinterCommandSet = new ActionRadioButton(
0376:                        new ActionSelectPrinter(ibmPrinterName, TYPE_IBM_OUTPUT));
0377:
0378:                txFilename = new JTextField();
0379:                encodingSelector = new EncodingSelector();
0380:
0381:                final ButtonGroup bg = new ButtonGroup();
0382:                bg.add(rbPlainPrinterCommandSet);
0383:                bg.add(rbIBMPrinterCommandSet);
0384:                bg.add(rbEpson9PrinterCommandSet);
0385:                bg.add(rbEpson24PrinterCommandSet);
0386:
0387:                getFormValidator().registerTextField(txFilename);
0388:                getFormValidator().registerButton(rbEpson24PrinterCommandSet);
0389:                getFormValidator().registerButton(rbEpson9PrinterCommandSet);
0390:                getFormValidator().registerButton(rbIBMPrinterCommandSet);
0391:                getFormValidator().registerButton(rbPlainPrinterCommandSet);
0392:
0393:                final JComponent exportPane = createExportPane();
0394:
0395:                final Configuration config = JFreeReportBoot.getInstance()
0396:                        .getGlobalConfig();
0397:                final boolean advancedSettingsTabAvail = "true"
0398:                        .equals(config
0399:                                .getConfigProperty("org.jfree.report.modules.gui.plaintext.AdvancedSettingsAvailable"));
0400:                if (advancedSettingsTabAvail) {
0401:                    final JTabbedPane tabbedPane = new JTabbedPane();
0402:                    tabbedPane
0403:                            .add(
0404:                                    getResources()
0405:                                            .getString(
0406:                                                    "plain-text-exportdialog.export-settings"), exportPane); //$NON-NLS-1$
0407:                    tabbedPane
0408:                            .add(
0409:                                    getResources()
0410:                                            .getString(
0411:                                                    "plain-text-exportdialog.advanced-settings"), createAdvancedPane()); //$NON-NLS-1$
0412:
0413:                    setContentPane(createContentPane(tabbedPane));
0414:                } else {
0415:                    setContentPane(createContentPane(exportPane));
0416:                }
0417:                clear();
0418:            }
0419:
0420:            private KeyedComboBoxModel loadEpson24Printers() {
0421:                final KeyedComboBoxModel epsonPrinters = new KeyedComboBoxModel();
0422:                final PrinterSpecificationManager spec24Manager = Epson24PinPrinterDriver
0423:                        .loadSpecificationManager();
0424:                final String[] printer24Names = spec24Manager.getPrinterNames();
0425:                Arrays.sort(printer24Names);
0426:                for (int i = 0; i < printer24Names.length; i++) {
0427:                    final PrinterSpecification pspec = spec24Manager
0428:                            .getPrinter(printer24Names[i]);
0429:                    epsonPrinters.add(pspec, pspec.getDisplayName());
0430:                }
0431:                return epsonPrinters;
0432:            }
0433:
0434:            private KeyedComboBoxModel loadEpson9Printers() {
0435:                final KeyedComboBoxModel epsonPrinters = new KeyedComboBoxModel();
0436:                final PrinterSpecificationManager spec9Manager = Epson9PinPrinterDriver
0437:                        .loadSpecificationManager();
0438:                final String[] printer9Names = spec9Manager.getPrinterNames();
0439:                Arrays.sort(printer9Names);
0440:                for (int i = 0; i < printer9Names.length; i++) {
0441:                    final PrinterSpecification pspec = spec9Manager
0442:                            .getPrinter(printer9Names[i]);
0443:                    epsonPrinters.add(pspec, pspec.getDisplayName());
0444:                }
0445:                return epsonPrinters;
0446:            }
0447:
0448:            public JStatusBar getStatusBar() {
0449:                return statusBar;
0450:            }
0451:
0452:            /**
0453:             * Creates the content pane for the export dialog.
0454:             *
0455:             * @return the created content pane.
0456:             */
0457:            private JComponent createExportPane() {
0458:                final JPanel contentPane = new JPanel();
0459:                contentPane.setLayout(new GridBagLayout());
0460:                contentPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3,
0461:                        3));
0462:
0463:                final JLabel lblFileName = new JLabel(getResources().getString(
0464:                        "plain-text-exportdialog.filename")); //$NON-NLS-1$
0465:                final JButton btnSelect = new ActionButton(
0466:                        new ActionSelectFile(getResources()));
0467:
0468:                GridBagConstraints gbc = new GridBagConstraints();
0469:                gbc.gridx = 0;
0470:                gbc.gridy = 0;
0471:                gbc.anchor = GridBagConstraints.WEST;
0472:                gbc.insets = new Insets(3, 1, 1, 1);
0473:                contentPane.add(lblFileName, gbc);
0474:
0475:                gbc = new GridBagConstraints();
0476:                gbc.fill = GridBagConstraints.HORIZONTAL;
0477:                gbc.weightx = 1;
0478:                gbc.gridx = 1;
0479:                gbc.gridy = 0;
0480:                gbc.ipadx = 120;
0481:                gbc.gridwidth = 2;
0482:                gbc.insets = new Insets(3, 1, 1, 1);
0483:                contentPane.add(txFilename, gbc);
0484:
0485:                gbc = new GridBagConstraints();
0486:                gbc.anchor = GridBagConstraints.NORTHWEST;
0487:                gbc.gridx = 3;
0488:                gbc.gridy = 0;
0489:                contentPane.add(btnSelect, gbc);
0490:
0491:                final JPanel advancedOptionsPane = new JPanel();
0492:                advancedOptionsPane.setLayout(new BorderLayout());
0493:                advancedOptionsPane.add(contentPane, BorderLayout.NORTH);
0494:                return advancedOptionsPane;
0495:            }
0496:
0497:            /**
0498:             * Creates the content pane for the export dialog.
0499:             *
0500:             * @return the created content pane.
0501:             */
0502:            private JComponent createAdvancedPane() {
0503:                final JPanel contentPane = new JPanel();
0504:                contentPane.setLayout(new GridBagLayout());
0505:                contentPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3,
0506:                        3));
0507:
0508:                final JLabel lblPrinterSelect = new JLabel(getResources()
0509:                        .getString("plain-text-exportdialog.printer")); //$NON-NLS-1$
0510:                final JLabel lblEncoding = new JLabel(getResources().getString(
0511:                        "plain-text-exportdialog.encoding")); //$NON-NLS-1$
0512:
0513:                final JLabel lblCharsPerInch = new JLabel(getResources()
0514:                        .getString("plain-text-exportdialog.chars-per-inch")); //$NON-NLS-1$
0515:                final JLabel lblLinesPerInch = new JLabel(getResources()
0516:                        .getString("plain-text-exportdialog.lines-per-inch")); //$NON-NLS-1$
0517:                final JLabel lblFontSettings = new JLabel(getResources()
0518:                        .getString("plain-text-exportdialog.font-settings")); //$NON-NLS-1$
0519:
0520:                GridBagConstraints gbc = new GridBagConstraints();
0521:                gbc.anchor = GridBagConstraints.WEST;
0522:                gbc.gridx = 0;
0523:                gbc.gridy = 0;
0524:                gbc.insets = new Insets(1, 1, 1, 1);
0525:                contentPane.add(lblEncoding, gbc);
0526:
0527:                gbc = new GridBagConstraints();
0528:                gbc.fill = GridBagConstraints.HORIZONTAL;
0529:                gbc.weightx = 0;
0530:                gbc.gridx = 1;
0531:                gbc.gridy = 0;
0532:                gbc.gridwidth = 3;
0533:                gbc.insets = new Insets(1, 1, 1, 1);
0534:                contentPane.add(encodingSelector, gbc);
0535:
0536:                gbc = new GridBagConstraints();
0537:                gbc.anchor = GridBagConstraints.WEST;
0538:                gbc.gridx = 0;
0539:                gbc.gridy = 1;
0540:                gbc.insets = new Insets(1, 1, 1, 1);
0541:                contentPane.add(lblPrinterSelect, gbc);
0542:
0543:                gbc = new GridBagConstraints();
0544:                gbc.fill = GridBagConstraints.HORIZONTAL;
0545:                gbc.weightx = 0;
0546:                gbc.gridx = 1;
0547:                gbc.gridy = 1;
0548:                gbc.gridwidth = 2;
0549:                gbc.insets = new Insets(1, 1, 1, 1);
0550:                contentPane.add(rbPlainPrinterCommandSet, gbc);
0551:
0552:                gbc = new GridBagConstraints();
0553:                gbc.fill = GridBagConstraints.HORIZONTAL;
0554:                gbc.weightx = 0;
0555:                gbc.gridx = 1;
0556:                gbc.gridy = 2;
0557:                gbc.gridwidth = 2;
0558:                gbc.insets = new Insets(1, 1, 1, 1);
0559:                contentPane.add(rbIBMPrinterCommandSet, gbc);
0560:
0561:                gbc = new GridBagConstraints();
0562:                gbc.fill = GridBagConstraints.HORIZONTAL;
0563:                gbc.weightx = 0;
0564:                gbc.gridx = 1;
0565:                gbc.gridy = 3;
0566:                gbc.gridwidth = 2;
0567:                gbc.insets = new Insets(1, 1, 1, 1);
0568:                contentPane.add(rbEpson9PrinterCommandSet, gbc);
0569:
0570:                gbc = new GridBagConstraints();
0571:                gbc.fill = GridBagConstraints.HORIZONTAL;
0572:                gbc.gridx = 3;
0573:                gbc.gridy = 3;
0574:                gbc.gridwidth = 1;
0575:                gbc.insets = new Insets(1, 1, 1, 1);
0576:                gbc.fill = GridBagConstraints.HORIZONTAL;
0577:                contentPane.add(cbEpson9PrinterType, gbc);
0578:
0579:                gbc = new GridBagConstraints();
0580:                gbc.fill = GridBagConstraints.HORIZONTAL;
0581:                gbc.weightx = 0;
0582:                gbc.gridx = 1;
0583:                gbc.gridy = 4;
0584:                gbc.gridwidth = 2;
0585:                gbc.insets = new Insets(1, 1, 1, 1);
0586:                contentPane.add(rbEpson24PrinterCommandSet, gbc);
0587:
0588:                gbc = new GridBagConstraints();
0589:                gbc.fill = GridBagConstraints.HORIZONTAL;
0590:                gbc.gridx = 3;
0591:                gbc.gridy = 4;
0592:                gbc.gridwidth = 1;
0593:                gbc.insets = new Insets(1, 1, 1, 1);
0594:                gbc.fill = GridBagConstraints.HORIZONTAL;
0595:                contentPane.add(cbEpson24PrinterType, gbc);
0596:
0597:                gbc = new GridBagConstraints();
0598:                gbc.fill = GridBagConstraints.NONE;
0599:                gbc.weightx = 0;
0600:                gbc.gridx = 0;
0601:                gbc.gridy = 6;
0602:                gbc.insets = new Insets(1, 1, 1, 1);
0603:                contentPane.add(lblFontSettings, gbc);
0604:
0605:                gbc = new GridBagConstraints();
0606:                gbc.fill = GridBagConstraints.HORIZONTAL;
0607:                gbc.weightx = 0;
0608:                gbc.gridx = 2;
0609:                gbc.gridy = 6;
0610:                gbc.insets = new Insets(1, 1, 1, 1);
0611:                contentPane.add(lblCharsPerInch, gbc);
0612:
0613:                gbc = new GridBagConstraints();
0614:                gbc.fill = GridBagConstraints.HORIZONTAL;
0615:                gbc.weightx = 0;
0616:                gbc.gridx = 1;
0617:                gbc.gridy = 6;
0618:                gbc.insets = new Insets(1, 1, 1, 1);
0619:                contentPane.add(cbCharsPerInch, gbc);
0620:
0621:                gbc = new GridBagConstraints();
0622:                gbc.fill = GridBagConstraints.HORIZONTAL;
0623:                gbc.weightx = 0;
0624:                gbc.gridx = 2;
0625:                gbc.gridy = 7;
0626:                gbc.insets = new Insets(1, 1, 1, 1);
0627:                contentPane.add(lblLinesPerInch, gbc);
0628:
0629:                gbc = new GridBagConstraints();
0630:                gbc.fill = GridBagConstraints.HORIZONTAL;
0631:                gbc.weightx = 0;
0632:                gbc.gridx = 1;
0633:                gbc.gridy = 7;
0634:                gbc.insets = new Insets(1, 1, 1, 1);
0635:                contentPane.add(cbLinesPerInch, gbc);
0636:
0637:                final JPanel advancedOptionsPane = new JPanel();
0638:                advancedOptionsPane.setLayout(new BorderLayout());
0639:                advancedOptionsPane.add(contentPane, BorderLayout.NORTH);
0640:                return advancedOptionsPane;
0641:
0642:            }
0643:
0644:            protected void updateEpson9Encoding() {
0645:                final PrinterSpecification spec = (PrinterSpecification) epson9Printers
0646:                        .getSelectedKey();
0647:                if (spec == null) {
0648:                    encodingSelector.setEncodings(PrinterSpecificationManager
0649:                            .getGenericPrinter(), getGuiContext().getLocale());
0650:                } else {
0651:                    encodingSelector.setEncodings(spec, getGuiContext()
0652:                            .getLocale());
0653:                }
0654:            }
0655:
0656:            protected void updateEpson24Encoding() {
0657:                final PrinterSpecification spec = (PrinterSpecification) epson9Printers
0658:                        .getSelectedKey();
0659:                if (spec == null) {
0660:                    encodingSelector.setEncodings(PrinterSpecificationManager
0661:                            .getGenericPrinter(), getGuiContext().getLocale());
0662:                } else {
0663:                    encodingSelector.setEncodings(spec, getGuiContext()
0664:                            .getLocale());
0665:                }
0666:            }
0667:
0668:            /**
0669:             * Sets the selected printer.
0670:             *
0671:             * @param type the type.
0672:             */
0673:            public void setSelectedPrinter(final int type) {
0674:                final Locale locale = getGuiContext().getLocale();
0675:
0676:                final String oldEncoding = getEncoding();
0677:                if (type == TYPE_EPSON9_OUTPUT) {
0678:                    rbEpson9PrinterCommandSet.setSelected(true);
0679:                    cbEpson9PrinterType.setEnabled(true);
0680:                    cbEpson24PrinterType.setEnabled(false);
0681:                    updateEpson9Encoding();
0682:                } else if (type == TYPE_EPSON24_OUTPUT) {
0683:                    rbEpson24PrinterCommandSet.setSelected(true);
0684:                    cbEpson24PrinterType.setEnabled(true);
0685:                    cbEpson9PrinterType.setEnabled(false);
0686:                    updateEpson24Encoding();
0687:                } else if (type == TYPE_IBM_OUTPUT) {
0688:                    rbIBMPrinterCommandSet.setSelected(true);
0689:                    cbEpson9PrinterType.setEnabled(false);
0690:                    cbEpson24PrinterType.setEnabled(false);
0691:                    encodingSelector
0692:                            .setEncodings(
0693:                                    new IBMCompatiblePrinterDriver.GenericIBMPrinterSpecification(),
0694:                                    locale);
0695:                } else if (type == TYPE_PLAIN_OUTPUT) {
0696:                    rbPlainPrinterCommandSet.setSelected(true);
0697:                    cbEpson9PrinterType.setEnabled(false);
0698:                    cbEpson24PrinterType.setEnabled(false);
0699:                    encodingSelector.setEncodings(
0700:                            new EncodingSelector.GenericPrinterSpecification(),
0701:                            locale);
0702:                } else {
0703:                    throw new IllegalArgumentException();
0704:                }
0705:                if (oldEncoding != null) {
0706:                    setEncoding(oldEncoding);
0707:                }
0708:            }
0709:
0710:            /**
0711:             * Returns the selected printer.
0712:             *
0713:             * @return The printer type.
0714:             */
0715:            public int getSelectedPrinter() {
0716:                if (rbPlainPrinterCommandSet.isSelected()) {
0717:                    return TYPE_PLAIN_OUTPUT;
0718:                }
0719:                if (rbEpson9PrinterCommandSet.isSelected()) {
0720:                    return TYPE_EPSON9_OUTPUT;
0721:                }
0722:                if (rbEpson24PrinterCommandSet.isSelected()) {
0723:                    return TYPE_EPSON24_OUTPUT;
0724:                }
0725:                return TYPE_IBM_OUTPUT;
0726:            }
0727:
0728:            /**
0729:             * Returns the filename.
0730:             *
0731:             * @return the name of the file where to save the file.
0732:             */
0733:            public String getFilename() {
0734:                return txFilename.getText();
0735:            }
0736:
0737:            /**
0738:             * Defines the filename of the file.
0739:             *
0740:             * @param filename the filename of the file
0741:             */
0742:            public void setFilename(final String filename) {
0743:                this .txFilename.setText(filename);
0744:            }
0745:
0746:            /**
0747:             * clears all selections, input fields and set the selected encryption level
0748:             * to none.
0749:             */
0750:            public void clear() {
0751:                txFilename.setText(""); //$NON-NLS-1$
0752:                setSelectedPrinter(TYPE_PLAIN_OUTPUT);
0753:                cbEpson9PrinterType.setEnabled(false);
0754:                cbEpson9PrinterType.setSelectedItem(Epson9PinPrinterDriver
0755:                        .getDefaultPrinter());
0756:                cbEpson24PrinterType.setEnabled(false);
0757:                cbEpson24PrinterType.setSelectedItem(Epson24PinPrinterDriver
0758:                        .getDefaultPrinter());
0759:                cbCharsPerInch.setSelectedItem(CPI_10);
0760:                cbLinesPerInch.setSelectedItem(LPI_6);
0761:                setEncoding(EncodingRegistry.getPlatformDefaultEncoding());
0762:            }
0763:
0764:            /**
0765:             * Returns the lines-per-inch setting.
0766:             *
0767:             * @return The lines-per-inch setting.
0768:             */
0769:            public float getLinesPerInch() {
0770:                final Float i = (Float) cbLinesPerInch.getSelectedItem();
0771:                if (i == null) {
0772:                    return LPI_6.floatValue();
0773:                }
0774:                return i.floatValue();
0775:            }
0776:
0777:            /**
0778:             * Sets the lines per inch.
0779:             *
0780:             * @param lpi the lines per inch.
0781:             */
0782:            public void setLinesPerInch(final float lpi) {
0783:                final Float lpiObj = new Float(lpi);
0784:                final ComboBoxModel model = cbLinesPerInch.getModel();
0785:                for (int i = 0; i < model.getSize(); i++) {
0786:                    if (lpiObj.equals(model.getElementAt(i))) {
0787:                        cbLinesPerInch.setSelectedIndex(i);
0788:                        return;
0789:                    }
0790:                }
0791:                throw new IllegalArgumentException(
0792:                        messages
0793:                                .getErrorString(
0794:                                        "PlainTextExportDialog.ERROR_0001_NO_SUCH_LPI", String.valueOf(lpi))); //$NON-NLS-1$ //$NON-NLS-2$
0795:            }
0796:
0797:            /**
0798:             * Returns the characters-per-inch setting.
0799:             *
0800:             * @return The characters-per-inch setting.
0801:             */
0802:            public float getCharsPerInch() {
0803:                final Float i = (Float) cbCharsPerInch.getSelectedItem();
0804:                if (i == null) {
0805:                    return CPI_10.floatValue();
0806:                }
0807:                return i.floatValue();
0808:            }
0809:
0810:            /**
0811:             * Sets the characters per inch.
0812:             *
0813:             * @param cpi the characters per inch.
0814:             */
0815:            public void setCharsPerInch(final float cpi) {
0816:                final Float cpiObj = new Float(cpi);
0817:                final ComboBoxModel model = cbCharsPerInch.getModel();
0818:                for (int i = 0; i < model.getSize(); i++) {
0819:                    if (cpiObj.equals(model.getElementAt(i))) {
0820:                        cbCharsPerInch.setSelectedIndex(i);
0821:                        return;
0822:                    }
0823:                }
0824:                if (messages == null) {
0825:                    messages = new Messages(
0826:                            PlainTextExportPlugin.BASE_RESOURCE_CLASS);
0827:                }
0828:                throw new IllegalArgumentException(
0829:                        messages
0830:                                .getErrorString(
0831:                                        "PlainTextExportDialog.ERROR_0002_NO_SUCH_CPI", String.valueOf(cpi))); //$NON-NLS-1$ //$NON-NLS-2$
0832:            }
0833:
0834:            /**
0835:             * Returns the encoding.
0836:             *
0837:             * @return The encoding.
0838:             */
0839:            public String getEncoding() {
0840:                return encodingSelector.getSelectedEncoding();
0841:            }
0842:
0843:            /**
0844:             * Sets the encoding.
0845:             *
0846:             * @param encoding the encoding.
0847:             */
0848:            public void setEncoding(final String encoding) {
0849:                if (encoding == null) {
0850:                    throw new NullPointerException(getResources().getString(
0851:                            "PlainTextExportDialog.ERROR_0003_NULL_ENCODING")); //$NON-NLS-1$
0852:                }
0853:                encodingSelector.setSelectedEncoding(encoding);
0854:            }
0855:
0856:            protected void setDialogContents(final Configuration config) {
0857:                setEncoding(config.getConfigProperty(
0858:                        PlainTextPageableModule.ENCODING,
0859:                        PlainTextPageableModule.ENCODING_DEFAULT));
0860:                setSelected9PinPrinterModel(config.getConfigProperty(
0861:                        Epson9PinPrinterDriver.EPSON_9PIN_PRINTER_TYPE,
0862:                        getSelected9PinPrinterModel()));
0863:                setSelected24PinPrinterModel(config.getConfigProperty(
0864:                        Epson24PinPrinterDriver.EPSON_24PIN_PRINTER_TYPE,
0865:                        getSelected24PinPrinterModel()));
0866:                final String mode = config
0867:                        .getConfigProperty("org.jfree.report.modules.gui.plaintext.ExportType"); //$NON-NLS-1$
0868:                if ("9pin".equals(mode)) //$NON-NLS-1$
0869:                {
0870:                    setSelectedPrinter(TYPE_EPSON9_OUTPUT);
0871:                } else if ("24pin".equals(mode)) //$NON-NLS-1$
0872:                {
0873:                    setSelectedPrinter(TYPE_EPSON24_OUTPUT);
0874:                } else if ("ibm".equals(mode)) //$NON-NLS-1$
0875:                {
0876:                    setSelectedPrinter(TYPE_IBM_OUTPUT);
0877:                } else {
0878:                    setSelectedPrinter(TYPE_PLAIN_OUTPUT);
0879:                }
0880:
0881:                try {
0882:                    final String lpi = config
0883:                            .getConfigProperty(PlainTextPageableModule.LINES_PER_INCH);
0884:                    setLinesPerInch(StringUtil.parseFloat(lpi, 6));
0885:                } catch (IllegalArgumentException e) {
0886:                    // ignore
0887:                }
0888:
0889:                try {
0890:                    final String cpi = config
0891:                            .getConfigProperty(PlainTextPageableModule.CHARS_PER_INCH);
0892:                    setCharsPerInch(StringUtil.parseFloat(cpi, 10));
0893:                } catch (IllegalArgumentException e) {
0894:                    // ignore
0895:                }
0896:
0897:                final String defaultFileName = config
0898:                        .getConfigProperty("org.jfree.report.modules.gui.plaintext.FileName"); //$NON-NLS-1$
0899:                if (defaultFileName != null) {
0900:                    setFilename(resolvePath(defaultFileName).getAbsolutePath());
0901:                }
0902:            }
0903:
0904:            /**
0905:             * Stores the input from the dialog into the report configuration of the
0906:             * report.
0907:             */
0908:            protected Configuration grabDialogContents(final boolean full) {
0909:                final DefaultConfiguration config = new DefaultConfiguration();
0910:
0911:                config.setConfigProperty(PlainTextPageableModule.ENCODING,
0912:                        getEncoding());
0913:                config.setConfigProperty(
0914:                        PlainTextPageableModule.CHARS_PER_INCH, String
0915:                                .valueOf(getCharsPerInch()));
0916:                config.setConfigProperty(
0917:                        PlainTextPageableModule.LINES_PER_INCH, String
0918:                                .valueOf(getLinesPerInch()));
0919:                config.setConfigProperty(
0920:                        Epson9PinPrinterDriver.EPSON_9PIN_PRINTER_TYPE,
0921:                        getSelected9PinPrinterModel());
0922:                config.setConfigProperty(
0923:                        Epson24PinPrinterDriver.EPSON_24PIN_PRINTER_TYPE,
0924:                        getSelected24PinPrinterModel());
0925:
0926:                if (full) {
0927:                    switch (getSelectedPrinter()) {
0928:                    case TYPE_EPSON24_OUTPUT: {
0929:                        config
0930:                                .setConfigProperty(
0931:                                        "org.jfree.report.modules.gui.plaintext.ExportType", "24pin"); //$NON-NLS-1$ //$NON-NLS-2$
0932:                        break;
0933:                    }
0934:                    case TYPE_EPSON9_OUTPUT: {
0935:                        config
0936:                                .setConfigProperty(
0937:                                        "org.jfree.report.modules.gui.plaintext.ExportType", "9pin"); //$NON-NLS-1$ //$NON-NLS-2$
0938:                        break;
0939:                    }
0940:                    case TYPE_IBM_OUTPUT: {
0941:                        config
0942:                                .setConfigProperty(
0943:                                        "org.jfree.report.modules.gui.plaintext.ExportType", "ibm"); //$NON-NLS-1$ //$NON-NLS-2$
0944:                        break;
0945:                    }
0946:                    case TYPE_PLAIN_OUTPUT: {
0947:                        config
0948:                                .setConfigProperty(
0949:                                        "org.jfree.report.modules.gui.plaintext.ExportType", "plain"); //$NON-NLS-1$ //$NON-NLS-2$
0950:                        break;
0951:                    }
0952:                    default:
0953:                        throw new IllegalStateException();
0954:                    }
0955:                    config
0956:                            .setConfigProperty(
0957:                                    "org.jfree.report.modules.gui.plaintext.FileName", getFilename()); //$NON-NLS-1$
0958:
0959:                }
0960:                return config;
0961:            }
0962:
0963:            protected String getConfigurationSuffix() {
0964:                return "_plaintextexport"; //$NON-NLS-1$
0965:            }
0966:
0967:            protected String getResourceBaseName() {
0968:                return PlainTextExportPlugin.BASE_RESOURCE_CLASS;
0969:            }
0970:
0971:            /**
0972:             * Validates the contents of the dialog's input fields. If the selected file
0973:             * exists, it is also checked for validity.
0974:             *
0975:             * @return true, if the input is valid, false otherwise
0976:             */
0977:            public boolean performValidate() {
0978:                getStatusBar().clear();
0979:
0980:                final String filename = getFilename();
0981:                if (filename.trim().length() == 0) {
0982:                    getStatusBar().setStatus(
0983:                            StatusType.ERROR,
0984:                            getResources().getString(
0985:                                    "plain-text-exportdialog.targetIsEmpty")); //$NON-NLS-1$
0986:                    return false;
0987:                }
0988:                final File f = new File(filename);
0989:                if (f.exists()) {
0990:                    if (f.isFile() == false) {
0991:                        getStatusBar()
0992:                                .setStatus(
0993:                                        StatusType.ERROR,
0994:                                        getResources()
0995:                                                .getString(
0996:                                                        "plain-text-exportdialog.targetIsNoFile")); //$NON-NLS-1$
0997:                        return false;
0998:                    }
0999:                    if (f.canWrite() == false) {
1000:                        getStatusBar()
1001:                                .setStatus(
1002:                                        StatusType.ERROR,
1003:                                        getResources()
1004:                                                .getString(
1005:                                                        "plain-text-exportdialog.targetIsNotWritable")); //$NON-NLS-1$
1006:                        return false;
1007:                    }
1008:
1009:                    final String message = MessageFormat
1010:                            .format(
1011:                                    getResources()
1012:                                            .getString(
1013:                                                    "plain-text-exportdialog.targetOverwriteWarning"), new Object[] { filename }); //$NON-NLS-1$
1014:                    getStatusBar().setStatus(StatusType.WARNING, message);
1015:
1016:                }
1017:
1018:                return true;
1019:            }
1020:
1021:            protected boolean performConfirm() {
1022:                final String filename = getFilename();
1023:                final File f = new File(filename);
1024:                if (f.exists()) {
1025:                    final String key1 = "plain-text-exportdialog.targetOverwriteConfirmation"; //$NON-NLS-1$
1026:                    final String key2 = "plain-text-exportdialog.targetOverwriteTitle"; //$NON-NLS-1$
1027:                    if (JOptionPane.showConfirmDialog(this , MessageFormat
1028:                            .format(getResources().getString(key1),
1029:                                    new Object[] { getFilename() }),
1030:                            getResources().getString(key2),
1031:                            JOptionPane.YES_NO_OPTION,
1032:                            JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
1033:                        return false;
1034:                    }
1035:                }
1036:                return true;
1037:            }
1038:
1039:            /**
1040:             * Warning: Might return null!
1041:             *
1042:             * @return
1043:             */
1044:            public String getSelected9PinPrinterModel() {
1045:                return (String) cbEpson9PrinterType.getSelectedItem();
1046:            }
1047:
1048:            public String getSelected24PinPrinterModel() {
1049:                return (String) cbEpson24PrinterType.getSelectedItem();
1050:            }
1051:
1052:            public void setSelected9PinPrinterModel(
1053:                    final String selectedPrinterModel) {
1054:                final int size = epson9Printers.getSize();
1055:                for (int i = 0; i < size; i++) {
1056:                    final PrinterSpecification spec = (PrinterSpecification) epson9Printers
1057:                            .getKeyAt(i);
1058:                    if (spec.getDisplayName().equals(selectedPrinterModel)) {
1059:                        epson9Printers.setSelectedKey(spec);
1060:                        return;
1061:                    }
1062:                }
1063:                epson9Printers.setSelectedKey(null);
1064:            }
1065:
1066:            public void setSelected24PinPrinterModel(
1067:                    final String selectedPrinterModel) {
1068:                final int size = epson24Printers.getSize();
1069:                for (int i = 0; i < size; i++) {
1070:                    final PrinterSpecification spec = (PrinterSpecification) epson24Printers
1071:                            .getKeyAt(i);
1072:                    if (spec.getDisplayName().equals(selectedPrinterModel)) {
1073:                        epson24Printers.setSelectedKey(spec);
1074:                        return;
1075:                    }
1076:                }
1077:                epson24Printers.setSelectedKey(null);
1078:            }
1079:
1080:            protected String getConfigurationPrefix() {
1081:                return "org.jfree.report.modules.gui.plaintext."; //$NON-NLS-1$
1082:            }
1083:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.