001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * HtmlDirExportDialog.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.html;
030:
031: import java.awt.BorderLayout;
032: import java.awt.Dialog;
033: import java.awt.Frame;
034: import java.awt.GridBagConstraints;
035: import java.awt.GridBagLayout;
036: import java.awt.Insets;
037: import java.awt.event.ActionEvent;
038: import java.io.File;
039: import java.text.MessageFormat;
040: import java.util.Locale;
041: import java.util.ResourceBundle;
042: import javax.swing.AbstractAction;
043: import javax.swing.Action;
044: import javax.swing.JCheckBox;
045: import javax.swing.JComboBox;
046: import javax.swing.JFileChooser;
047: import javax.swing.JLabel;
048: import javax.swing.JOptionPane;
049: import javax.swing.JPanel;
050: import javax.swing.JTabbedPane;
051: import javax.swing.JTextField;
052:
053: import org.jfree.fonts.encoding.EncodingRegistry;
054: import org.jfree.report.JFreeReportBoot;
055: import org.jfree.report.modules.gui.commonswing.AbstractExportDialog;
056: import org.jfree.report.modules.gui.commonswing.EncodingComboBoxModel;
057: import org.jfree.report.modules.gui.commonswing.JStatusBar;
058: import org.jfree.report.modules.gui.commonswing.StatusType;
059: import org.jfree.ui.FilesystemFilter;
060: import org.jfree.ui.action.ActionButton;
061: import org.jfree.util.Configuration;
062: import org.jfree.util.DefaultConfiguration;
063: import org.jfree.util.StringUtils;
064:
065: /**
066: * A dialog that is used to perform the printing of a report into an HTML file.
067: *
068: * @author Heiko Evermann
069: */
070: public class HtmlDirExportDialog extends AbstractExportDialog {
071: /**
072: * The 'HTML encoding' property key.
073: */
074: public static final String HTML_OUTPUT_ENCODING = "org.jfree.report.modules.output.table.html.Encoding"; //$NON-NLS-1$
075: /**
076: * A default value of the 'HTML encoding' property key.
077: */
078: public static final String HTML_OUTPUT_ENCODING_DEFAULT = "UTF-16"; //$NON-NLS-1$
079:
080: /**
081: * An action to select the export target file.
082: */
083: private class ActionSelectDirFile extends AbstractAction {
084: /**
085: * Default constructor.
086: */
087: protected ActionSelectDirFile(final ResourceBundle resources) {
088: putValue(Action.NAME, resources
089: .getString("htmlexportdialog.selectFile")); //$NON-NLS-1$
090: }
091:
092: /**
093: * Receives notification that the action has occurred.
094: *
095: * @param e the action event.
096: */
097: public void actionPerformed(final ActionEvent e) {
098: performSelectFile();
099: }
100: }
101:
102: /**
103: * Filename text field.
104: */
105: private JTextField txFilename;
106:
107: /**
108: * Data file name field.
109: */
110: private JTextField txDataFilename;
111:
112: /**
113: * Title text field.
114: */
115: private JTextField txTitle;
116:
117: /**
118: * Author text field.
119: */
120: private JTextField txAuthor;
121:
122: /**
123: * A combo-box for selecting the encoding.
124: */
125: private JComboBox cbEncoding;
126:
127: /**
128: * The encoding data model.
129: */
130: private EncodingComboBoxModel encodingModel;
131:
132: /**
133: * A check-box for selecting 'strict layout'.
134: */
135: private JCheckBox cbxStrictLayout;
136:
137: /**
138: * A check-box for...
139: */
140: private JCheckBox cbxCopyExternalReferences;
141:
142: /**
143: * A file chooser for directory and stream export.
144: */
145: private JFileChooser fileChooserHtml;
146:
147: private static final String HTML_FILE_EXTENSION = ".html"; //$NON-NLS-1$
148: private static final String HTM_FILE_EXTENSION = ".htm"; //$NON-NLS-1$
149:
150: private JStatusBar statusBar;
151: private JTextField txKeywords;
152: private JTextField txDescription;
153:
154: /**
155: * Creates a new HTML save dialog.
156: *
157: * @param owner the dialog owner.
158: */
159: public HtmlDirExportDialog(final Frame owner) {
160: super (owner);
161: initConstructor();
162: }
163:
164: /**
165: * Creates a new HTML export dialog.
166: *
167: * @param owner the dialog owner.
168: */
169: public HtmlDirExportDialog(final Dialog owner) {
170: super (owner);
171: initConstructor();
172: }
173:
174: /**
175: * Creates a new HTML save dialog. The created dialog is modal.
176: */
177: public HtmlDirExportDialog() {
178: initConstructor();
179: }
180:
181: /**
182: * Initialisation.
183: */
184: private void initConstructor() {
185: statusBar = new JStatusBar();
186: setTitle(getResources().getString(
187: "htmlexportdialog.dialogtitle")); //$NON-NLS-1$
188: initialize();
189: clear();
190: }
191:
192: public JStatusBar getStatusBar() {
193: return statusBar;
194: }
195:
196: private JPanel createExportPanel() {
197: final JLabel lblDirFileName = new JLabel(getResources()
198: .getString("htmlexportdialog.filename")); //$NON-NLS-1$
199: final JLabel lblDirDataFileName = new JLabel(getResources()
200: .getString("htmlexportdialog.datafilename")); //$NON-NLS-1$
201:
202: final JPanel contentPane = new JPanel();
203: contentPane.setLayout(new GridBagLayout());
204:
205: GridBagConstraints gbc = new GridBagConstraints();
206: gbc.fill = GridBagConstraints.NONE;
207: gbc.anchor = GridBagConstraints.WEST;
208: gbc.gridx = 0;
209: gbc.gridy = 1;
210: gbc.insets = new Insets(1, 1, 1, 5);
211: contentPane.add(lblDirFileName, gbc);
212:
213: gbc = new GridBagConstraints();
214: gbc.anchor = GridBagConstraints.WEST;
215: gbc.fill = GridBagConstraints.HORIZONTAL;
216: gbc.gridx = 1;
217: gbc.gridy = 1;
218: gbc.gridwidth = 1;
219: gbc.weightx = 1;
220: gbc.insets = new Insets(1, 1, 1, 1);
221: contentPane.add(txFilename, gbc);
222:
223: gbc = new GridBagConstraints();
224: gbc.anchor = GridBagConstraints.WEST;
225: gbc.fill = GridBagConstraints.HORIZONTAL;
226: gbc.gridx = 2;
227: gbc.gridy = 1;
228: contentPane.add(new ActionButton(
229: new HtmlDirExportDialog.ActionSelectDirFile(
230: getResources())), gbc);
231:
232: gbc = new GridBagConstraints();
233: gbc.fill = GridBagConstraints.NONE;
234: gbc.anchor = GridBagConstraints.WEST;
235: gbc.gridx = 0;
236: gbc.gridy = 2;
237: gbc.insets = new Insets(1, 1, 1, 5);
238: contentPane.add(lblDirDataFileName, gbc);
239:
240: gbc = new GridBagConstraints();
241: gbc.anchor = GridBagConstraints.WEST;
242: gbc.fill = GridBagConstraints.HORIZONTAL;
243: gbc.gridx = 1;
244: gbc.gridy = 2;
245: gbc.gridwidth = 1;
246: gbc.weightx = 1;
247: gbc.insets = new Insets(1, 1, 1, 1);
248: contentPane.add(txDataFilename, gbc);
249:
250: final JPanel advancedOptionsPane = new JPanel();
251: advancedOptionsPane.setLayout(new BorderLayout());
252: advancedOptionsPane.add(contentPane, BorderLayout.NORTH);
253: return advancedOptionsPane;
254: }
255:
256: private JPanel createExportOptionsPanel() {
257: final JLabel lblEncoding = new JLabel(getResources().getString(
258: "htmlexportdialog.encoding")); //$NON-NLS-1$
259: final JPanel contentPane = new JPanel();
260: contentPane.setLayout(new GridBagLayout());
261:
262: GridBagConstraints gbc = new GridBagConstraints();
263: gbc.anchor = GridBagConstraints.WEST;
264: gbc.fill = GridBagConstraints.NONE;
265: gbc.gridx = 1;
266: gbc.gridy = 2;
267: gbc.gridwidth = 1;
268: gbc.weightx = 1;
269: gbc.insets = new Insets(1, 1, 1, 1);
270: contentPane.add(cbxCopyExternalReferences, gbc);
271:
272: gbc = new GridBagConstraints();
273: gbc.anchor = GridBagConstraints.WEST;
274: gbc.gridx = 0;
275: gbc.gridy = 0;
276: gbc.insets = new Insets(1, 1, 1, 1);
277: contentPane.add(lblEncoding, gbc);
278:
279: gbc = new GridBagConstraints();
280: gbc.fill = GridBagConstraints.HORIZONTAL;
281: gbc.weightx = 1;
282: gbc.gridx = 1;
283: gbc.gridy = 0;
284: gbc.gridwidth = 2;
285: gbc.insets = new Insets(1, 1, 1, 1);
286: contentPane.add(cbEncoding, gbc);
287:
288: gbc = new GridBagConstraints();
289: gbc.anchor = GridBagConstraints.WEST;
290: gbc.fill = GridBagConstraints.HORIZONTAL;
291: gbc.gridx = 1;
292: gbc.gridy = 1;
293: gbc.gridwidth = 2;
294: gbc.insets = new Insets(1, 1, 1, 1);
295: contentPane.add(cbxStrictLayout, gbc);
296:
297: final JPanel advancedOptionsPane = new JPanel();
298: advancedOptionsPane.setLayout(new BorderLayout());
299: advancedOptionsPane.add(contentPane, BorderLayout.NORTH);
300: return advancedOptionsPane;
301: }
302:
303: private JPanel createMetaDataPanel() {
304: final JPanel contentPane = new JPanel();
305: contentPane.setLayout(new GridBagLayout());
306:
307: final JLabel lblAuthor = new JLabel(getResources().getString(
308: "htmlexportdialog.author")); //$NON-NLS-1$
309: final JLabel lblTitel = new JLabel(getResources().getString(
310: "htmlexportdialog.title")); //$NON-NLS-1$
311: final JLabel lblKeywords = new JLabel(getResources().getString(
312: "htmlexportdialog.keywords")); //$NON-NLS-1$
313: final JLabel lblDescription = new JLabel(getResources()
314: .getString("htmlexportdialog.description")); //$NON-NLS-1$
315:
316: GridBagConstraints gbc = new GridBagConstraints();
317: gbc.gridx = 0;
318: gbc.gridy = 0;
319: gbc.anchor = GridBagConstraints.WEST;
320: gbc.insets = new Insets(3, 1, 1, 1);
321: contentPane.add(lblTitel, gbc);
322:
323: gbc = new GridBagConstraints();
324: gbc.anchor = GridBagConstraints.WEST;
325: gbc.gridx = 0;
326: gbc.gridy = 1;
327: gbc.insets = new Insets(1, 1, 1, 1);
328: contentPane.add(lblAuthor, gbc);
329:
330: gbc = new GridBagConstraints();
331: gbc.anchor = GridBagConstraints.WEST;
332: gbc.gridx = 0;
333: gbc.gridy = 2;
334: gbc.insets = new Insets(1, 1, 1, 1);
335: contentPane.add(lblKeywords, gbc);
336:
337: gbc = new GridBagConstraints();
338: gbc.anchor = GridBagConstraints.WEST;
339: gbc.gridx = 0;
340: gbc.gridy = 3;
341: gbc.insets = new Insets(1, 1, 1, 1);
342: contentPane.add(lblDescription, gbc);
343:
344: gbc = new GridBagConstraints();
345: gbc.fill = GridBagConstraints.HORIZONTAL;
346: gbc.weightx = 1;
347: gbc.gridx = 1;
348: gbc.gridy = 0;
349: gbc.gridwidth = 2;
350: gbc.insets = new Insets(3, 1, 1, 1);
351: contentPane.add(txTitle, gbc);
352:
353: gbc = new GridBagConstraints();
354: gbc.fill = GridBagConstraints.HORIZONTAL;
355: gbc.weightx = 1;
356: gbc.gridx = 1;
357: gbc.gridy = 1;
358: gbc.gridwidth = 2;
359: gbc.insets = new Insets(1, 1, 1, 1);
360: contentPane.add(txAuthor, gbc);
361:
362: gbc = new GridBagConstraints();
363: gbc.fill = GridBagConstraints.HORIZONTAL;
364: gbc.weightx = 1;
365: gbc.gridx = 1;
366: gbc.gridy = 2;
367: gbc.gridwidth = 2;
368: gbc.insets = new Insets(1, 1, 1, 1);
369: contentPane.add(txKeywords, gbc);
370:
371: gbc = new GridBagConstraints();
372: gbc.fill = GridBagConstraints.HORIZONTAL;
373: gbc.weightx = 1;
374: gbc.gridx = 1;
375: gbc.gridy = 3;
376: gbc.gridwidth = 2;
377: gbc.insets = new Insets(1, 1, 1, 1);
378: contentPane.add(txDescription, gbc);
379:
380: final JPanel advancedOptionsPane = new JPanel();
381: advancedOptionsPane.setLayout(new BorderLayout());
382: advancedOptionsPane.add(contentPane, BorderLayout.NORTH);
383: return advancedOptionsPane;
384: }
385:
386: /**
387: * Initializes the Swing components of this dialog.
388: */
389: private void initialize() {
390:
391: txAuthor = new JTextField();
392: txAuthor.setColumns(40);
393: txTitle = new JTextField();
394: txTitle.setColumns(40);
395: txKeywords = new JTextField();
396: txKeywords.setColumns(40);
397: txDescription = new JTextField();
398: txDescription.setColumns(40);
399: txFilename = new JTextField();
400: txFilename.setColumns(40);
401: txDataFilename = new JTextField();
402: txDataFilename.setColumns(40);
403:
404: encodingModel = EncodingComboBoxModel.createDefaultModel(Locale
405: .getDefault());
406: encodingModel.sort();
407:
408: cbEncoding = new JComboBox(encodingModel);
409: cbxStrictLayout = new JCheckBox(getResources().getString(
410: "htmlexportdialog.strict-layout")); //$NON-NLS-1$
411: cbxCopyExternalReferences = new JCheckBox(getResources()
412: .getString("htmlexportdialog.copy-external-references")); //$NON-NLS-1$
413:
414: getFormValidator().registerButton(cbxStrictLayout);
415: getFormValidator().registerTextField(txFilename);
416: getFormValidator().registerTextField(txDataFilename);
417: getFormValidator().registerComboBox(cbEncoding);
418:
419: final JPanel exportPane = createExportPanel();
420:
421: final Configuration config = JFreeReportBoot.getInstance()
422: .getGlobalConfig();
423: final boolean advancedSettingsTabAvail = "true"
424: .equals(config
425: .getConfigProperty("org.jfree.report.modules.gui.html.file.AdvancedSettingsAvailable"));
426: final boolean metaDataSettingsTabAvail = "true"
427: .equals(config
428: .getConfigProperty("org.jfree.report.modules.gui.html.file.MetaDataSettingsAvailable"));
429: if (advancedSettingsTabAvail || metaDataSettingsTabAvail) {
430: final JTabbedPane tabbedPane = new JTabbedPane();
431: tabbedPane.add(getResources().getString(
432: "htmlexportdialog.export-settings"), exportPane); //$NON-NLS-1$
433: if (metaDataSettingsTabAvail) {
434: tabbedPane
435: .add(
436: getResources()
437: .getString(
438: "htmlexportdialog.metadata-settings"), createMetaDataPanel()); //$NON-NLS-1$
439: }
440: if (advancedSettingsTabAvail) {
441: tabbedPane
442: .add(
443: getResources()
444: .getString(
445: "htmlexportdialog.advanced-settings"), createExportOptionsPanel()); //$NON-NLS-1$
446: }
447:
448: setContentPane(createContentPane(tabbedPane));
449: } else {
450: setContentPane(createContentPane(exportPane));
451: }
452: }
453:
454: /**
455: * Returns the title of the HTML file.
456: *
457: * @return the title
458: */
459: public String getHTMLTitle() {
460: return txTitle.getText();
461: }
462:
463: /**
464: * Defines the title of the HTML file.
465: *
466: * @param title the title
467: */
468: public void setHTMLTitle(final String title) {
469: this .txTitle.setText(title);
470: }
471:
472: /**
473: * Gets the author of the dialog. This is not yet implemented in the HTML-Target.
474: *
475: * @return the name of the author of this report.
476: */
477: public String getAuthor() {
478: return txAuthor.getText();
479: }
480:
481: /**
482: * Defines the Author of the report. Any freeform text is valid. This defaults to the value of the systemProperty
483: * "user.name".
484: *
485: * @param author the name of the author.
486: */
487: public void setAuthor(final String author) {
488: this .txAuthor.setText(author);
489: }
490:
491: public void setKeywords(final String keywords) {
492: this .txKeywords.setText(keywords);
493: }
494:
495: public String getKeywords() {
496: return this .txKeywords.getText();
497: }
498:
499: public void setDescription(final String description) {
500: this .txDescription.setText(description);
501: }
502:
503: public String getDescription() {
504: return this .txDescription.getText();
505: }
506:
507: /**
508: * Clears all selections and input fields.
509: */
510: public void clear() {
511: txAuthor.setText(JFreeReportBoot.getInstance()
512: .getGlobalConfig().getConfigProperty("user.name", "")); //$NON-NLS-1$ //$NON-NLS-2$
513: txFilename.setText(""); //$NON-NLS-1$
514: txDataFilename.setText(""); //$NON-NLS-1$
515: txTitle.setText(""); //$NON-NLS-1$
516: txDescription.setText(""); //$NON-NLS-1$
517: txKeywords.setText(""); //$NON-NLS-1$
518: cbEncoding
519: .setSelectedIndex(encodingModel
520: .indexOf(EncodingRegistry
521: .getPlatformDefaultEncoding()));
522: cbxCopyExternalReferences.setSelected(false);
523: cbxStrictLayout.setSelected(false);
524: }
525:
526: /**
527: * Returns a new (and not connected to the default config from the job) configuration containing all properties from
528: * the dialog.
529: *
530: * @param full
531: * @return
532: */
533: protected Configuration grabDialogContents(final boolean full) {
534: final DefaultConfiguration p = new DefaultConfiguration();
535: if (full) {
536: p
537: .setConfigProperty(
538: "org.jfree.report.modules.gui.html.file.DataDirectory", getDataFilename()); //$NON-NLS-1$
539: p
540: .setConfigProperty(
541: "org.jfree.report.modules.gui.html.file.TargetFileName", getFilename()); //$NON-NLS-1$
542: }
543:
544: p
545: .setConfigProperty(
546: "org.jfree.report.modules.output.table.html.Keywords", getKeywords()); //$NON-NLS-1$
547: p
548: .setConfigProperty(
549: "org.jfree.report.modules.output.table.html.Description", getDescription()); //$NON-NLS-1$
550: p
551: .setConfigProperty(
552: "org.jfree.report.modules.output.table.html.Author", getAuthor()); //$NON-NLS-1$
553: p
554: .setConfigProperty(
555: "org.jfree.report.modules.output.table.html.Encoding", getEncoding()); //$NON-NLS-1$
556: p
557: .setConfigProperty(
558: "org.jfree.report.modules.output.table.html.Title", getHTMLTitle()); //$NON-NLS-1$
559: p
560: .setConfigProperty(
561: "org.jfree.report.modules.output.table.html.StrictLayout", String.valueOf(isStrictLayout())); //$NON-NLS-1$
562: return p;
563: }
564:
565: protected void setDialogContents(final Configuration p) {
566: setHTMLTitle(p.getConfigProperty(
567: "org.jfree.report.modules.output.table.html.Title", //$NON-NLS-1$
568: p.getConfigProperty("org.jfree.report.metadata.Title"))); //$NON-NLS-1$
569: setAuthor(p
570: .getConfigProperty(
571: "org.jfree.report.modules.output.table.html.Author", //$NON-NLS-1$
572: p
573: .getConfigProperty("org.jfree.report.metadata.Author"))); //$NON-NLS-1$
574: setKeywords(p
575: .getConfigProperty(
576: "org.jfree.report.modules.output.table.html.Keywords", //$NON-NLS-1$
577: p
578: .getConfigProperty("org.jfree.report.metadata.Keywords"))); //$NON-NLS-1$
579: setDescription(p
580: .getConfigProperty(
581: "org.jfree.report.modules.output.table.html.Description", //$NON-NLS-1$
582: p
583: .getConfigProperty("org.jfree.report.metadata.Description"))); //$NON-NLS-1$
584:
585: setStrictLayout("true".equals(p.getConfigProperty //$NON-NLS-1$
586: ("org.jfree.report.modules.output.table.html.StrictLayout"))); //$NON-NLS-1$
587:
588: final String encoding = p.getConfigProperty(
589: "org.jfree.report.modules.output.table.html.Encoding", //$NON-NLS-1$
590: EncodingRegistry.getPlatformDefaultEncoding());
591: encodingModel.ensureEncodingAvailable(encoding);
592: setEncoding(encoding);
593:
594: setDataFilename(p
595: .getConfigProperty(
596: "org.jfree.report.modules.gui.html.file.DataDirectory", "")); //$NON-NLS-1$ //$NON-NLS-2$
597: setFilename(p
598: .getConfigProperty(
599: "org.jfree.report.modules.gui.html.file.TargetFileName", "")); //$NON-NLS-1$ //$NON-NLS-2$
600: }
601:
602: /**
603: * Returns the directory data file name.
604: *
605: * @return The file name.
606: */
607: public String getDataFilename() {
608: return txDataFilename.getText();
609: }
610:
611: /**
612: * Sets the directory data file name.
613: *
614: * @param dirFilename the file name.
615: */
616: public void setDataFilename(final String dirFilename) {
617: this .txDataFilename.setText(dirFilename);
618: }
619:
620: /**
621: * Returns the directory file name.
622: *
623: * @return The directory file name.
624: */
625: public String getFilename() {
626: return txFilename.getText();
627: }
628:
629: /**
630: * Sets the directory file name.
631: *
632: * @param dirFilename the file name.
633: */
634: public void setFilename(final String dirFilename) {
635: this .txFilename.setText(dirFilename);
636: }
637:
638: /**
639: * Returns the setting of the 'strict layout' check-box.
640: *
641: * @return A boolean.
642: */
643: public boolean isStrictLayout() {
644: return cbxStrictLayout.isSelected();
645: }
646:
647: /**
648: * Sets the 'strict layout' check-box.
649: *
650: * @param s boolean.
651: */
652: public void setStrictLayout(final boolean s) {
653: cbxStrictLayout.setSelected(s);
654: }
655:
656: /**
657: * Returns the selected encoding.
658: *
659: * @return The encoding name.
660: */
661: public String getEncoding() {
662: if (cbEncoding.getSelectedIndex() == -1) {
663: return EncodingRegistry.getPlatformDefaultEncoding();
664: } else {
665: return encodingModel.getEncoding(cbEncoding
666: .getSelectedIndex());
667: }
668: }
669:
670: /**
671: * Sets the encoding.
672: *
673: * @param encoding the encoding name.
674: */
675: public void setEncoding(final String encoding) {
676: cbEncoding.setSelectedIndex(encodingModel.indexOf(encoding));
677: }
678:
679: /**
680: * Selects a file to use as target for the report processing.
681: */
682: protected void performSelectFile() {
683: final File file = new File(getFilename());
684:
685: if (fileChooserHtml == null) {
686: fileChooserHtml = new JFileChooser();
687: fileChooserHtml
688: .addChoosableFileFilter(new FilesystemFilter(
689: new String[] {
690: HtmlDirExportDialog.HTML_FILE_EXTENSION,
691: HtmlDirExportDialog.HTM_FILE_EXTENSION },
692: getResources().getString(
693: "htmlexportdialog.html-documents"), true)); //$NON-NLS-1$
694: fileChooserHtml.setMultiSelectionEnabled(false);
695: }
696:
697: fileChooserHtml.setCurrentDirectory(file);
698: fileChooserHtml.setSelectedFile(file);
699: final int option = fileChooserHtml.showSaveDialog(this );
700: if (option == JFileChooser.APPROVE_OPTION) {
701: final File selFile = fileChooserHtml.getSelectedFile();
702: String selFileName = selFile.getAbsolutePath();
703:
704: // Test if ends on html
705: if ((StringUtils.endsWithIgnoreCase(selFileName,
706: HtmlDirExportDialog.HTML_FILE_EXTENSION) == false)
707: && (StringUtils.endsWithIgnoreCase(selFileName,
708: HtmlDirExportDialog.HTM_FILE_EXTENSION) == false)) {
709: selFileName = selFileName
710: + HtmlDirExportDialog.HTML_FILE_EXTENSION;
711: }
712: setFilename(selFileName);
713: }
714: }
715:
716: /**
717: * Validates the contents of the dialog's input fields. If the selected file exists, it is also checked for validity.
718: *
719: * @return true, if the input is valid, false otherwise
720: */
721: public boolean performValidate() {
722: getStatusBar().clear();
723:
724: final String filename = getFilename();
725: if (filename.trim().length() == 0) {
726: getStatusBar().setStatus(
727: StatusType.ERROR,
728: getResources().getString(
729: "htmlexportdialog.targetIsEmpty")); //$NON-NLS-1$
730: return false;
731: }
732: final File f = new File(filename);
733: if (f.exists()) {
734: if (f.isFile() == false) {
735: getStatusBar().setStatus(
736: StatusType.ERROR,
737: getResources().getString(
738: "htmlexportdialog.targetIsNoFile")); //$NON-NLS-1$
739: return false;
740: }
741: if (f.canWrite() == false) {
742: getStatusBar()
743: .setStatus(
744: StatusType.ERROR,
745: getResources()
746: .getString(
747: "htmlexportdialog.targetIsNotWritable")); //$NON-NLS-1$
748: return false;
749: }
750:
751: final String message = MessageFormat.format(getResources()
752: .getString("htmlexportdialog.targetExistsWarning"), //$NON-NLS-1$
753: new Object[] { filename });
754: getStatusBar().setStatus(StatusType.WARNING, message);
755: }
756:
757: final File dataDir = new File(getDataFilename())
758: .getAbsoluteFile();
759: if (dataDir.exists()) {
760: // dataDirectory does exist ... if no directory : fail
761: if (dataDir.isDirectory() == false) {
762: getStatusBar()
763: .setStatus(
764: StatusType.ERROR,
765: getResources()
766: .getString(
767: "htmlexportdialog.targetDataDirIsNoDirectory")); //$NON-NLS-1$
768: return false;
769: }
770: }
771:
772: return true;
773: }
774:
775: protected boolean performConfirm() {
776: final String filename = getFilename();
777: final File f = new File(filename).getAbsoluteFile();
778: if (f.exists()) {
779: final String key1 = "htmlexportdialog.targetOverwriteConfirmation"; //$NON-NLS-1$
780: final String key2 = "htmlexportdialog.targetOverwriteTitle"; //$NON-NLS-1$
781: if (JOptionPane.showConfirmDialog(this , MessageFormat
782: .format(getResources().getString(key1),
783: new Object[] { getFilename() }),
784: getResources().getString(key2),
785: JOptionPane.YES_NO_OPTION,
786: JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
787: return false;
788: }
789: }
790:
791: final File dataDir = createDataDir(f.getParentFile(),
792: getDataFilename());
793: if (dataDir.exists() == false) {
794: final String dataDirKey1 = "htmlexportdialog.targetCreateDataDirConfirmation"; //$NON-NLS-1$
795: final String dataDirKey2 = "htmlexportdialog.targetCreateDataDirTitle"; //$NON-NLS-1$
796: if (JOptionPane.showConfirmDialog(this , MessageFormat
797: .format(getResources().getString(dataDirKey1),
798: new Object[] { getDataFilename() }),
799: getResources().getString(dataDirKey2),
800: JOptionPane.YES_NO_OPTION,
801: JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
802: return false;
803: }
804: }
805: return true;
806: }
807:
808: private File createDataDir(final File targetFile,
809: final String dataDirectory) {
810: final File dataDirFile = new File(dataDirectory);
811: if (dataDirFile.isAbsolute()) {
812: return dataDirFile;
813: }
814:
815: return new File(targetFile.getParentFile(), dataDirectory);
816: }
817:
818: protected String getConfigurationSuffix() {
819: return "_html-dir-export"; //$NON-NLS-1$
820: }
821:
822: protected String getResourceBaseName() {
823: return HtmlZipExportPlugin.BASE_RESOURCE_CLASS;
824: }
825:
826: protected String getConfigurationPrefix() {
827: return "org.jfree.report.modules.gui.html.file."; //$NON-NLS-1$
828: }
829: }
|