1:
31:
32: package ;
33:
34: import ;
35: import ;
36: import ;
37: import ;
38: import ;
39: import ;
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66:
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79:
80:
85: public class PdfExportDialog extends AbstractExportDialog
86: {
87:
88: private static final int CBMODEL_NOPRINTING = 0;
89:
90:
91: private static final int CBMODEL_DEGRADED = 1;
92:
93:
94: private static final int CBMODEL_FULL = 2;
95:
96:
100: private class ActionSecuritySelection extends AbstractAction
101: {
102:
103: protected ActionSecuritySelection()
104: {
105: }
106:
107:
112: public void actionPerformed(final ActionEvent e)
113: {
114: updateSecurityPanelEnabled();
115: }
116: }
117:
118:
119: private class ActionSelectFile extends AbstractAction
120: {
121:
122: protected ActionSelectFile(final ResourceBundle resources)
123: {
124: putValue(Action.NAME, resources.getString("pdfsavedialog.selectFile"));
125: }
126:
127:
132: public void actionPerformed(final ActionEvent e)
133: {
134: performSelectFile();
135: }
136: }
137:
138:
139: private JRadioButton rbSecurityNone;
140:
141:
142: private JRadioButton rbSecurity40Bit;
143:
144:
145: private JRadioButton rbSecurity128Bit;
146:
147:
148: private JTextField txUserPassword;
149:
150:
151: private JTextField txOwnerPassword;
152:
153:
154: private JTextField txConfUserPassword;
155:
156:
157: private JTextField txConfOwnerPassword;
158:
159:
160: private JCheckBox cxAllowCopy;
161:
162:
163: private JCheckBox cxAllowScreenReaders;
164:
165:
166: private JComboBox cbAllowPrinting;
167:
168:
169: private JCheckBox cxAllowAssembly;
170:
171:
172: private JCheckBox cxAllowModifyContents;
173:
174:
175: private JCheckBox cxAllowModifyAnnotations;
176:
177:
178: private JCheckBox cxAllowFillIn;
179:
180:
181: private EncodingComboBoxModel encodingModel;
182:
183:
184: private JFileChooser fileChooser;
185: private static final String PDF_FILE_EXTENSION = ".pdf";
186: private JStatusBar statusBar;
187: private JTextField txFilename;
188: private DefaultComboBoxModel printingModel;
189:
190:
195: public PdfExportDialog()
196: {
197: initializeComponents();
198: }
199:
200:
208: public PdfExportDialog(final Frame owner)
209: {
210: super(owner);
211: initializeComponents();
212: }
213:
214:
221: public PdfExportDialog(final Dialog owner)
222: {
223: super(owner);
224: initializeComponents();
225: }
226:
227: private void initializeComponents ()
228: {
229: final JPanel mainPanel = new JPanel();
230: mainPanel.setLayout(new GridBagLayout());
231: mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
232:
233: final JLabel lblFileName = new JLabel(getResources().getString("pdfsavedialog.filename"));
234: final JLabel lblEncoding = new JLabel(getResources().getString("pdfsavedialog.encoding"));
235:
236: final JButton btnSelect = new ActionButton(new ActionSelectFile(getResources()));
237: txFilename = new JTextField();
238: statusBar = new JStatusBar();
239:
240: encodingModel = EncodingComboBoxModel.createDefaultModel(Locale.getDefault());
241: encodingModel.addEncodingUnchecked("Identity-H", "PDF-Unicode encoding");
242: encodingModel.addEncodingUnchecked("Identity-V", "PDF-Unicode encoding");
243: encodingModel.sort();
244:
245: final JComboBox cbEncoding = new JComboBox(encodingModel);
246:
247: GridBagConstraints gbc = new GridBagConstraints();
248: gbc.gridx = 0;
249: gbc.gridy = 0;
250: gbc.anchor = GridBagConstraints.WEST;
251: gbc.insets = new Insets(3, 1, 1, 1);
252: mainPanel.add(lblFileName, gbc);
253:
254: gbc = new GridBagConstraints();
255: gbc.fill = GridBagConstraints.HORIZONTAL;
256: gbc.weightx = 1;
257: gbc.gridx = 1;
258: gbc.gridy = 0;
259: gbc.ipadx = 120;
260: gbc.insets = new Insets(3, 1, 1, 1);
261: mainPanel.add(txFilename, gbc);
262:
263: gbc = new GridBagConstraints();
264: gbc.anchor = GridBagConstraints.NORTHWEST;
265: gbc.gridx = 2;
266: gbc.gridy = 0;
267: mainPanel.add(btnSelect, gbc);
268:
269: gbc = new GridBagConstraints();
270: gbc.anchor = GridBagConstraints.WEST;
271: gbc.gridx = 0;
272: gbc.gridy = 1;
273: gbc.insets = new Insets(1, 1, 1, 1);
274: mainPanel.add(lblEncoding, gbc);
275:
276: gbc = new GridBagConstraints();
277: gbc.fill = GridBagConstraints.HORIZONTAL;
278: gbc.weightx = 1;
279: gbc.gridx = 1;
280: gbc.gridy = 1;
281: gbc.ipadx = 120;
282: gbc.insets = new Insets(1, 1, 1, 1);
283: mainPanel.add(cbEncoding, gbc);
284:
285: final JButton btnCancel = new ActionButton(getCancelAction());
286: final JButton btnConfirm = new ActionButton(getConfirmAction());
287: final JPanel buttonPanel = new JPanel();
288: buttonPanel.setLayout(new GridLayout(1, 2, 5, 5));
289: buttonPanel.add(btnConfirm);
290: buttonPanel.add(btnCancel);
291: btnConfirm.setDefaultCapable(true);
292: getRootPane().setDefaultButton(btnConfirm);
293: buttonPanel.registerKeyboardAction(getConfirmAction(),
294: KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
295: JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
296:
297: final JPanel buttonCarrier = new JPanel();
298: buttonCarrier.setLayout(new FlowLayout(FlowLayout.RIGHT));
299: buttonCarrier.add(buttonPanel);
300:
301: gbc = new GridBagConstraints();
302: gbc.fill = GridBagConstraints.NONE;
303: gbc.anchor = GridBagConstraints.EAST;
304: gbc.weightx = 1;
305: gbc.gridx = 0;
306: gbc.gridwidth = 3;
307: gbc.gridy = 6;
308: gbc.insets = new Insets(10, 0, 0, 0);
309:
310: final JPanel mainPaneCarrier = new JPanel();
311: mainPaneCarrier.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
312: mainPaneCarrier.setLayout(new BorderLayout());
313: mainPaneCarrier.add(mainPanel, BorderLayout.NORTH);
314:
315: final JPanel securityPaneCarrier = new JPanel();
316: securityPaneCarrier.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
317: securityPaneCarrier.setLayout(new BorderLayout());
318: securityPaneCarrier.add(createSecurityPanel(), BorderLayout.NORTH);
319:
320: final JTabbedPane tabbedPane = new JTabbedPane();
321: tabbedPane.add("Export-Settings", mainPaneCarrier);
322: tabbedPane.add("Security", securityPaneCarrier);
323:
324: final JPanel contentPane = new JPanel();
325: contentPane.setLayout(new BorderLayout());
326: contentPane.add(tabbedPane, BorderLayout.CENTER);
327: contentPane.add(buttonCarrier, BorderLayout.SOUTH);
328:
329: final JPanel contentWithStatus = new JPanel();
330: contentWithStatus.setLayout(new BorderLayout());
331: contentWithStatus.add(contentPane, BorderLayout.CENTER);
332: contentWithStatus.add(getStatusBar(), BorderLayout.SOUTH);
333:
334: setContentPane(contentWithStatus);
335:
336: getFormValidator().registerTextField(txFilename);
337: getFormValidator().registerTextField(txConfOwnerPassword);
338: getFormValidator().registerTextField(txConfUserPassword);
339: getFormValidator().registerTextField(txUserPassword);
340: getFormValidator().registerTextField(txOwnerPassword);
341:
342: }
343:
344:
345: public JStatusBar getStatusBar()
346: {
347: return statusBar;
348: }
349:
350: protected boolean performConfirm()
351: {
352: final String filename = txFilename.getText();
353: final File f = new File(filename);
354: if (f.exists())
355: {
356: final String key1 = "pdfsavedialog.targetOverwriteConfirmation";
357: final String key2 = "pdfsavedialog.targetOverwriteTitle";
358: if (JOptionPane.showConfirmDialog(this,
359: MessageFormat.format(getResources().getString(key1),
360: new Object[]{txFilename.getText()}),
361: getResources().getString(key2),
362: JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)
363: == JOptionPane.NO_OPTION)
364: {
365: return false;
366: }
367: }
368:
369: if (getEncryptionValue().equals(PdfOutputModule.SECURITY_ENCRYPTION_128BIT)
370: || getEncryptionValue().equals(
371: PdfOutputModule.SECURITY_ENCRYPTION_40BIT))
372: {
373: if (txOwnerPassword.getText().trim().length() == 0)
374: {
375: if (JOptionPane.showConfirmDialog(this,
376: getResources().getString("pdfsavedialog.ownerpasswordEmpty"),
377: getResources().getString("pdfsavedialog.warningTitle"),
378: JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE)
379: == JOptionPane.NO_OPTION)
380: {
381: return false;
382: }
383: }
384: }
385: return true;
386: }
387:
388: protected boolean performValidate()
389: {
390: getStatusBar().clear();
391:
392: final String filename = txFilename.getText();
393: if (filename.trim().length() == 0)
394: {
395: getStatusBar().setStatus(JStatusBar.TYPE_ERROR,
396: getResources().getString("pdfsavedialog.targetIsEmpty"));
397: return false;
398: }
399: final File f = new File(filename);
400: if (f.exists())
401: {
402: if (f.isFile() == false)
403: {
404: getStatusBar().setStatus(JStatusBar.TYPE_ERROR,
405: getResources().getString("pdfsavedialog.targetIsNoFile"));
406: return false;
407: }
408: if (f.canWrite() == false)
409: {
410: getStatusBar().setStatus(JStatusBar.TYPE_ERROR,
411: getResources().getString("pdfsavedialog.targetIsNotWritable"));
412: return false;
413: }
414:
415: final String message = MessageFormat.format(getResources().getString
416: ("pdfsavedialog.targetOverwriteWarning"),
417: new Object[]{filename});
418: getStatusBar().setStatus(JStatusBar.TYPE_WARNING, message);
419: }
420:
421: if (getEncryptionValue().equals(PdfOutputModule.SECURITY_ENCRYPTION_128BIT)
422: || getEncryptionValue().equals(
423: PdfOutputModule.SECURITY_ENCRYPTION_40BIT))
424: {
425: if (txUserPassword.getText().equals(
426: txConfUserPassword.getText()) == false)
427: {
428: getStatusBar().setStatus(JStatusBar.TYPE_ERROR,
429: getResources().getString("pdfsavedialog.userpasswordNoMatch"));
430: return false;
431: }
432: if (txOwnerPassword.getText().equals(
433: txConfOwnerPassword.getText()) == false)
434: {
435: getStatusBar().setStatus(JStatusBar.TYPE_ERROR,
436: getResources().getString("pdfsavedialog.ownerpasswordNoMatch"));
437: return false;
438: }
439: }
440:
441: return true;
442: }
443:
444: protected void initializeFromJob(final ReportJob job, final GuiContext guiContext)
445: {
446: statusBar.setIconTheme(guiContext.getIconTheme());
447:
448:
449:
450:
451:
452:
453: }
454:
455: protected String getConfigurationPrefix()
456: {
457: return "org.jfree.report.modules.gui.common.pdf.";
458: }
459:
460:
466: protected Configuration grabDialogContents(final boolean full)
467: {
468: final DefaultConfiguration config = new DefaultConfiguration();
469:
470: final String prefix = getConfigurationPrefix();
471: config.setConfigProperty(prefix + "TargetFileName", txFilename.getText());
472: config.setConfigProperty(prefix + "Encoding", encodingModel.getSelectedEncoding());
473: config.getConfigProperty(prefix + "security.PrintLevel", getPrintLevel());
474: config.getConfigProperty(prefix + "security.Encryption", getEncryptionValue());
475:
476:
477: config.getConfigProperty(prefix + "security.UserPassword", txUserPassword.getText());
478: config.getConfigProperty(prefix + "security.OwnerPassword", txOwnerPassword.getText());
479:
480: config.setConfigProperty(prefix + "security.AllowAssembly",
481: String.valueOf(cxAllowAssembly.isSelected()));
482: config.setConfigProperty(prefix + "security.AllowCopy",
483: String.valueOf(cxAllowCopy.isSelected()));
484: config.setConfigProperty(prefix + "security.AllowFillIn",
485: String.valueOf(cxAllowFillIn.isSelected()));
486: config.setConfigProperty(prefix + "security.AllowModifyAnnotations",
487: String.valueOf(cxAllowModifyAnnotations.isSelected()));
488: config.setConfigProperty(prefix + "security.AllowModifyContents",
489: String.valueOf(cxAllowModifyContents.isSelected()));
490: config.setConfigProperty(prefix + "security.AllowScreenReaders",
491: String.valueOf(cxAllowScreenReaders.isSelected()));
492: return config;
493: }
494:
495: protected void setDialogContents(final Configuration config)
496: {
497: final String prefix = getConfigurationPrefix();
498: txFilename.setText(config.getConfigProperty(prefix + "TargetFileName"));
499: final String encoding = config.getConfigProperty(prefix + "Encoding");
500: if (encoding != null && encoding.length() > 0)
501: {
502: encodingModel.setSelectedEncoding(encoding);
503: }
504: setPrintLevel(config.getConfigProperty(prefix + "security.PrintLevel"));
505: setEncryptionValue(config.getConfigProperty(prefix + "security.Encryption"));
506:
507: txUserPassword.setText(config.getConfigProperty(prefix + "security.UserPassword"));
508: txOwnerPassword.setText(config.getConfigProperty(prefix + "security.OwnerPassword"));
509: txConfUserPassword.setText(config.getConfigProperty(prefix + "security.UserPassword"));
510: txConfOwnerPassword.setText(config.getConfigProperty(prefix + "security.OwnerPassword"));
511:
512: cxAllowAssembly.setSelected("true".equals
513: (config.getConfigProperty(prefix + "security.AllowAssembly")));
514: cxAllowCopy.setSelected("true".equals
515: (config.getConfigProperty(prefix + "security.AllowCopy")));
516: cxAllowFillIn.setSelected("true".equals
517: (config.getConfigProperty(prefix + "security.AllowFillIn")));
518: cxAllowModifyAnnotations.setSelected("true".equals
519: (config.getConfigProperty(prefix + "security.AllowModifyAnnotations")));
520: cxAllowModifyContents.setSelected("true".equals
521: (config.getConfigProperty(prefix + "security.AllowModifyContents")));
522: cxAllowScreenReaders.setSelected("true".equals
523: (config.getConfigProperty(prefix + "security.AllowScreenReaders")));
524: }
525:
526: protected String getConfigurationSuffix()
527: {
528: return "_pdf_export";
529: }
530:
531: public void clear()
532: {
533: txConfOwnerPassword.setText("");
534: txConfUserPassword.setText("");
535: txFilename.setText("");
536: txOwnerPassword.setText("");
537: txUserPassword.setText("");
538:
539: cxAllowAssembly.setSelected(false);
540: cxAllowCopy.setSelected(false);
541: cbAllowPrinting.setSelectedIndex(CBMODEL_NOPRINTING);
542: cxAllowFillIn.setSelected(false);
543: cxAllowModifyAnnotations.setSelected(false);
544: cxAllowModifyContents.setSelected(false);
545: cxAllowScreenReaders.setSelected(false);
546:
547: rbSecurityNone.setSelected(true);
548: updateSecurityPanelEnabled();
549:
550: final String plattformDefaultEncoding = EncodingRegistry.getPlatformDefaultEncoding();
551: encodingModel.setSelectedEncoding(plattformDefaultEncoding);
552: }
553:
554: protected String getResourceBaseName()
555: {
556: return SwingPdfModule.BUNDLE_NAME;
557: }
558:
559:
560:
564: protected void updateSecurityPanelEnabled()
565: {
566: final boolean b = (rbSecurityNone.isSelected() == false);
567: txUserPassword.setEnabled(b);
568: txOwnerPassword.setEnabled(b);
569: txConfOwnerPassword.setEnabled(b);
570: txConfUserPassword.setEnabled(b);
571: cxAllowAssembly.setEnabled(b);
572: cxAllowCopy.setEnabled(b);
573: cbAllowPrinting.setEnabled(b);
574: cxAllowFillIn.setEnabled(b);
575: cxAllowModifyAnnotations.setEnabled(b);
576: cxAllowModifyContents.setEnabled(b);
577: cxAllowScreenReaders.setEnabled(b);
578: }
579:
580:
581: private void createSecurityPanelComponents()
582: {
583: txUserPassword = new JPasswordField();
584: txConfUserPassword = new JPasswordField();
585: txOwnerPassword = new JPasswordField();
586: txConfOwnerPassword = new JPasswordField();
587:
588: cxAllowCopy = new JCheckBox(getResources().getString(
589: "pdfsavedialog.allowCopy"));
590: cbAllowPrinting = new JComboBox(getPrintingComboBoxModel());
591: cxAllowScreenReaders =
592: new JCheckBox(getResources().getString(
593: "pdfsavedialog.allowScreenreader"));
594:
595: cxAllowAssembly = new JCheckBox(getResources().getString(
596: "pdfsavedialog.allowAssembly"));
597: cxAllowModifyContents =
598: new JCheckBox(getResources().getString(
599: "pdfsavedialog.allowModifyContents"));
600: cxAllowModifyAnnotations =
601: new JCheckBox(getResources().getString(
602: "pdfsavedialog.allowModifyAnnotations"));
603: cxAllowFillIn = new JCheckBox(getResources().getString(
604: "pdfsavedialog.allowFillIn"));
605:
606: }
607:
608:
613: private JPanel createSecurityPanel()
614: {
615: final JPanel securityPanel = new JPanel();
616: securityPanel.setLayout(new GridBagLayout());
617:
618: createSecurityPanelComponents();
619:
620: final JLabel lblUserPass = new JLabel(getResources().getString(
621: "pdfsavedialog.userpassword"));
622: final JLabel lblUserPassConfirm =
623: new JLabel(getResources().getString(
624: "pdfsavedialog.userpasswordconfirm"));
625: final JLabel lblOwnerPass =
626: new JLabel(getResources().getString("pdfsavedialog.ownerpassword"));
627: final JLabel lblOwnerPassConfirm =
628: new JLabel(getResources().getString(
629: "pdfsavedialog.ownerpasswordconfirm"));
630: final JLabel lbAllowPrinting =
631: new JLabel(getResources().getString("pdfsavedialog.allowPrinting"));
632:
633: GridBagConstraints gbc = new GridBagConstraints();
634: gbc.fill = GridBagConstraints.HORIZONTAL;
635: gbc.weightx = 1;
636: gbc.gridx = 0;
637: gbc.gridwidth = 4;
638: gbc.gridy = 0;
639: gbc.insets = new Insets(5, 5, 5, 5);
640: securityPanel.add(createSecurityConfigPanel(), gbc);
641:
642: gbc = new GridBagConstraints();
643: gbc.anchor = GridBagConstraints.WEST;
644: gbc.gridx = 0;
645: gbc.gridy = 1;
646: gbc.insets = new Insets(5, 5, 5, 5);
647: securityPanel.add(lblUserPass, gbc);
648:
649: gbc = new GridBagConstraints();
650: gbc.fill = GridBagConstraints.HORIZONTAL;
651: gbc.weightx = 1;
652: gbc.gridx = 1;
653: gbc.gridy = 1;
654: gbc.ipadx = 120;
655: gbc.insets = new Insets(5, 5, 5, 5);
656: securityPanel.add(txUserPassword, gbc);
657:
658: gbc = new GridBagConstraints();
659: gbc.anchor = GridBagConstraints.WEST;
660: gbc.gridx = 0;
661: gbc.gridy = 2;
662: gbc.insets = new Insets(5, 5, 5, 5);
663: securityPanel.add(lblOwnerPass, gbc);
664:
665: gbc = new GridBagConstraints();
666: gbc.fill = GridBagConstraints.HORIZONTAL;
667: gbc.weightx = 1;
668: gbc.gridx = 1;
669: gbc.gridy = 2;
670: gbc.ipadx = 120;
671: gbc.insets = new Insets(5, 5, 5, 5);
672: securityPanel.add(txOwnerPassword, gbc);
673:
674: gbc = new GridBagConstraints();
675: gbc.anchor = GridBagConstraints.WEST;
676: gbc.gridx = 2;
677: gbc.gridy = 1;
678: gbc.insets = new Insets(5, 5, 5, 5);
679: securityPanel.add(lblUserPassConfirm, gbc);
680:
681: gbc = new GridBagConstraints();
682: gbc.fill = GridBagConstraints.HORIZONTAL;
683: gbc.weightx = 1;
684: gbc.gridx = 3;
685: gbc.gridy = 1;
686: gbc.ipadx = 120;
687: gbc.insets = new Insets(5, 5, 5, 5);
688: securityPanel.add(txConfUserPassword, gbc);
689:
690: gbc = new GridBagConstraints();
691: gbc.anchor = GridBagConstraints.WEST;
692: gbc.gridx = 2;
693: gbc.gridy = 2;
694: gbc.insets = new Insets(5, 5, 5, 5);
695: securityPanel.add(lblOwnerPassConfirm, gbc);
696:
697: gbc = new GridBagConstraints();
698: gbc.fill = GridBagConstraints.HORIZONTAL;
699: gbc.weightx = 1;
700: gbc.gridx = 3;
701: gbc.gridy = 2;
702: gbc.ipadx = 120;
703: gbc.insets = new Insets(5, 5, 5, 5);
704: securityPanel.add(txConfOwnerPassword, gbc);
705:
706: gbc = new GridBagConstraints();
707: gbc.gridx = 0;
708: gbc.gridwidth = 2;
709: gbc.gridy = 3;
710: gbc.anchor = GridBagConstraints.WEST;
711: securityPanel.add(cxAllowCopy, gbc);
712:
713: gbc = new GridBagConstraints();
714: gbc.gridx = 0;
715: gbc.gridwidth = 2;
716: gbc.gridy = 4;
717: gbc.anchor = GridBagConstraints.WEST;
718: securityPanel.add(cxAllowScreenReaders, gbc);
719:
720: gbc = new GridBagConstraints();
721: gbc.gridx = 0;
722: gbc.gridwidth = 2;
723: gbc.gridy = 5;
724: gbc.anchor = GridBagConstraints.WEST;
725: securityPanel.add(cxAllowFillIn, gbc);
726:
727: gbc = new GridBagConstraints();
728: gbc.gridx = 2;
729: gbc.gridwidth = 2;
730: gbc.gridy = 3;
731: gbc.anchor = GridBagConstraints.WEST;
732: securityPanel.add(cxAllowAssembly, gbc);
733:
734: gbc = new GridBagConstraints();
735: gbc.gridx = 2;
736: gbc.gridwidth = 2;
737: gbc.gridy = 4;
738: gbc.anchor = GridBagConstraints.WEST;
739: securityPanel.add(cxAllowModifyContents, gbc);
740:
741: gbc = new GridBagConstraints();
742: gbc.gridx = 2;
743: gbc.gridwidth = 2;
744: gbc.gridy = 5;
745: gbc.anchor = GridBagConstraints.WEST;
746: securityPanel.add(cxAllowModifyAnnotations, gbc);
747:
748: gbc = new GridBagConstraints();
749: gbc.gridx = 0;
750: gbc.gridwidth = 1;
751: gbc.gridy = 6;
752: gbc.anchor = GridBagConstraints.WEST;
753: securityPanel.add(lbAllowPrinting, gbc);
754:
755: gbc = new GridBagConstraints();
756: gbc.gridx = 1;
757: gbc.gridwidth = 3;
758: gbc.gridy = 6;
759: gbc.anchor = GridBagConstraints.WEST;
760: securityPanel.add(cbAllowPrinting, gbc);
761:
762: return securityPanel;
763: }
764:
765:
771: private JPanel createSecurityConfigPanel()
772: {
773: rbSecurityNone = new JRadioButton(getResources().getString(
774: "pdfsavedialog.securityNone"));
775: rbSecurity40Bit = new JRadioButton(getResources().getString(
776: "pdfsavedialog.security40bit"));
777: rbSecurity128Bit = new JRadioButton(getResources().getString(
778: "pdfsavedialog.security128bit"));
779:
780: final Action securitySelectAction = new ActionSecuritySelection();
781: rbSecurityNone.addActionListener(securitySelectAction);
782: rbSecurity40Bit.addActionListener(securitySelectAction);
783: rbSecurity128Bit.addActionListener(securitySelectAction);
784:
785: rbSecurity128Bit.setSelected(true);
786:
787: final JPanel pnlSecurityConfig = new JPanel();
788: pnlSecurityConfig.setLayout(new GridLayout());
789: pnlSecurityConfig.add(rbSecurityNone);
790: pnlSecurityConfig.add(rbSecurity40Bit);
791: pnlSecurityConfig.add(rbSecurity128Bit);
792:
793: final ButtonGroup btGrpSecurity = new ButtonGroup();
794: btGrpSecurity.add(rbSecurity128Bit);
795: btGrpSecurity.add(rbSecurity40Bit);
796: btGrpSecurity.add(rbSecurityNone);
797:
798: return pnlSecurityConfig;
799: }
800:
801:
808: private DefaultComboBoxModel getPrintingComboBoxModel()
809: {
810: if (printingModel == null)
811: {
812: final Object[] data = {
813: getResources().getString("pdfsavedialog.option.noprinting"),
814: getResources().getString("pdfsavedialog.option.degradedprinting"),
815: getResources().getString("pdfsavedialog.option.fullprinting")
816: };
817: printingModel = new DefaultComboBoxModel(data);
818: }
819: return printingModel;
820: }
821:
822:
823:
824: protected void performSelectFile()
825: {
826:
827: if (fileChooser == null)
828: {
829: fileChooser = new JFileChooser();
830: final FilesystemFilter filter = new FilesystemFilter(PDF_FILE_EXTENSION,
831: "PDF Documents");
832: fileChooser.addChoosableFileFilter(filter);
833: fileChooser.setMultiSelectionEnabled(false);
834: }
835:
836: final File file = new File(txFilename.getText());
837: fileChooser.setCurrentDirectory(file);
838: fileChooser.setSelectedFile(file);
839: final int option = fileChooser.showSaveDialog(this);
840: if (option == JFileChooser.APPROVE_OPTION)
841: {
842: final File selFile = fileChooser.getSelectedFile();
843: String selFileName = selFile.getAbsolutePath();
844:
845:
846: if (selFileName.toLowerCase().endsWith(PDF_FILE_EXTENSION) == false)
847: {
848: selFileName = selFileName + PDF_FILE_EXTENSION;
849: }
850: txFilename.setText(selFileName);
851: }
852: }
853:
854:
862: public void setPrintLevel(final String printLevel)
863: {
864: if ("full".equals(printLevel))
865: {
866: this.cbAllowPrinting.setSelectedIndex(CBMODEL_FULL);
867: }
868: else if ("degraded".equals(printLevel))
869: {
870: this.cbAllowPrinting.setSelectedIndex(CBMODEL_DEGRADED);
871: }
872: else
873: {
874: this.cbAllowPrinting.setSelectedIndex(CBMODEL_NOPRINTING);
875: }
876: }
877:
878: public String getPrintLevel ()
879: {
880: if (cbAllowPrinting.getSelectedIndex() == CBMODEL_FULL)
881: {
882: return "full";
883: }
884: if (cbAllowPrinting.getSelectedIndex() == CBMODEL_DEGRADED)
885: {
886: return "degraded";
887: }
888: return "none";
889: }
890:
891:
892:
903: public String getEncryptionValue()
904: {
905: if (rbSecurity40Bit.isSelected())
906: {
907: return PdfOutputModule.SECURITY_ENCRYPTION_40BIT;
908: }
909: if (rbSecurity128Bit.isSelected())
910: {
911: return PdfOutputModule.SECURITY_ENCRYPTION_128BIT;
912: }
913: return PdfOutputModule.SECURITY_ENCRYPTION_NONE;
914: }
915:
916:
922: public void setEncryptionValue(final String b)
923: {
924: if (b != null)
925: {
926: if (b.equals(PdfOutputModule.SECURITY_ENCRYPTION_128BIT))
927: {
928: rbSecurity128Bit.setSelected(true);
929: updateSecurityPanelEnabled();
930: return;
931: }
932: else if (b.equals(PdfOutputModule.SECURITY_ENCRYPTION_40BIT))
933: {
934: rbSecurity40Bit.setSelected(true);
935: updateSecurityPanelEnabled();
936: return;
937: }
938: else if (b.equals(PdfOutputModule.SECURITY_ENCRYPTION_NONE) == false)
939: {
940: Log.warn("Invalid encryption value entered. " + b);
941: }
942: }
943: rbSecurityNone.setSelected(true);
944: updateSecurityPanelEnabled();
945: }
946: }