1 /*
2 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
64 import javax.swing.border.EmptyBorder;
65 import javax.swing.border.TitledBorder;
66 import javax.swing.event.ChangeEvent;
67 import javax.swing.event.ChangeListener;
68 import javax.swing.event.DocumentEvent;
69 import javax.swing.event.DocumentListener;
70 import javax.swing.event.PopupMenuEvent;
71 import javax.swing.event.PopupMenuListener;
72 import javax.swing.text.NumberFormatter;
73 import sun.print.SunPageSelection;
74 import java.awt.event.KeyEvent;
75 import java.net.URISyntaxException;
76 import java.lang.reflect.Field;
77
78
79 /**
80 * A class which implements a cross-platform print dialog.
81 *
82 * @author Chris Campbell
83 */
84 public class ServiceDialog extends JDialog implements ActionListener {
85
86 /**
87 * Waiting print status (user response pending).
88 */
89 public final static int WAITING = 0;
90
91 /**
92 * Approve print status (user activated "Print" or "OK").
93 */
94 public final static int APPROVE = 1;
95
96 /**
97 * Cancel print status (user activated "Cancel");
98 */
99 public final static int CANCEL = 2;
100
101 private static final String strBundle = "sun.print.resources.serviceui";
102 private static final Insets panelInsets = new Insets(6, 6, 6, 6);
103 private static final Insets compInsets = new Insets(3, 6, 3, 6);
290 handleEscKey(btnCancel);
291 pnlSouth.add(btnCancel);
292 c.add(pnlSouth, BorderLayout.SOUTH);
293
294 addWindowListener(new WindowAdapter() {
295 public void windowClosing(WindowEvent event) {
296 dispose(CANCEL);
297 }
298 });
299
300 getAccessibleContext().setAccessibleDescription(getMsg("dialog.pstitle"));
301 setResizable(false);
302 setLocation(x, y);
303 pack();
304 }
305
306 /**
307 * Performs Cancel when Esc key is pressed.
308 */
309 private void handleEscKey(JButton btnCancel) {
310 Action cancelKeyAction = new AbstractAction() {
311 public void actionPerformed(ActionEvent e) {
312 dispose(CANCEL);
313 }
314 };
315 KeyStroke cancelKeyStroke =
316 KeyStroke.getKeyStroke((char)KeyEvent.VK_ESCAPE, 0);
317 InputMap inputMap =
318 btnCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
319 ActionMap actionMap = btnCancel.getActionMap();
320
321 if (inputMap != null && actionMap != null) {
322 inputMap.put(cancelKeyStroke, "cancel");
323 actionMap.put("cancel", cancelKeyAction);
324 }
325 }
326
327
328 /**
329 * Returns the current status of the dialog (whether the user has selected
639 cont.add(comp);
640 }
641
642 /**
643 * Adds the AbstractButton to both the given ButtonGroup and Container
644 */
645 private static void addToBG(AbstractButton button, Container cont,
646 ButtonGroup bg)
647 {
648 bg.add(button);
649 cont.add(button);
650 }
651
652
653
654
655 /**
656 * The "General" tab. Includes the controls for PrintService,
657 * PageRange, and Copies/Collate.
658 */
659 private class GeneralPanel extends JPanel {
660
661 private PrintServicePanel pnlPrintService;
662 private PrintRangePanel pnlPrintRange;
663 private CopiesPanel pnlCopies;
664
665 public GeneralPanel() {
666 super();
667
668 GridBagLayout gridbag = new GridBagLayout();
669 GridBagConstraints c = new GridBagConstraints();
670
671 setLayout(gridbag);
672
673 c.fill = GridBagConstraints.BOTH;
674 c.insets = panelInsets;
675 c.weightx = 1.0;
676 c.weighty = 1.0;
677
678 c.gridwidth = GridBagConstraints.REMAINDER;
682 c.gridwidth = GridBagConstraints.RELATIVE;
683 pnlPrintRange = new PrintRangePanel();
684 addToGB(pnlPrintRange, this, gridbag, c);
685
686 c.gridwidth = GridBagConstraints.REMAINDER;
687 pnlCopies = new CopiesPanel();
688 addToGB(pnlCopies, this, gridbag, c);
689 }
690
691 public boolean isPrintToFileRequested() {
692 return (pnlPrintService.isPrintToFileSelected());
693 }
694
695 public void updateInfo() {
696 pnlPrintService.updateInfo();
697 pnlPrintRange.updateInfo();
698 pnlCopies.updateInfo();
699 }
700 }
701
702 private class PrintServicePanel extends JPanel
703 implements ActionListener, ItemListener, PopupMenuListener
704 {
705 private final String strTitle = getMsg("border.printservice");
706 private FilePermission printToFilePermission;
707 private JButton btnProperties;
708 private JCheckBox cbPrintToFile;
709 private JComboBox cbName;
710 private JLabel lblType, lblStatus, lblInfo;
711 private ServiceUIFactory uiFactory;
712 private boolean changedService = false;
713 private boolean filePermission;
714
715 public PrintServicePanel() {
716 super();
717
718 uiFactory = psCurrent.getServiceUIFactory();
719
720 GridBagLayout gridbag = new GridBagLayout();
721 GridBagConstraints c = new GridBagConstraints();
939 && dstSupported);
940
941 // setup PrintService information widgets
942 Attribute type = psCurrent.getAttribute(PrinterMakeAndModel.class);
943 if (type != null) {
944 lblType.setText(type.toString());
945 }
946 Attribute status =
947 psCurrent.getAttribute(PrinterIsAcceptingJobs.class);
948 if (status != null) {
949 lblStatus.setText(getMsg(status.toString()));
950 }
951 Attribute info = psCurrent.getAttribute(PrinterInfo.class);
952 if (info != null) {
953 lblInfo.setText(info.toString());
954 }
955 btnProperties.setEnabled(uiFactory != null);
956 }
957 }
958
959 private class PrintRangePanel extends JPanel
960 implements ActionListener, FocusListener
961 {
962 private final String strTitle = getMsg("border.printrange");
963 private final PageRanges prAll = new PageRanges(1, Integer.MAX_VALUE);
964 private JRadioButton rbAll, rbPages, rbSelect;
965 private JFormattedTextField tfRangeFrom, tfRangeTo;
966 private JLabel lblRangeTo;
967 private boolean prSupported;
968
969 public PrintRangePanel() {
970 super();
971
972 GridBagLayout gridbag = new GridBagLayout();
973 GridBagConstraints c = new GridBagConstraints();
974
975 setLayout(gridbag);
976 setBorder(BorderFactory.createTitledBorder(strTitle));
977
978 c.fill = GridBagConstraints.BOTH;
1151
1152 if (select == SunPageSelection.ALL) {
1153 rbAll.setSelected(true);
1154 } else if (select == SunPageSelection.SELECTION) {
1155 // Comment this for now - rbSelect is not initialized
1156 // because Selection button is not added.
1157 // See PrintRangePanel above.
1158
1159 //rbSelect.setSelected(true);
1160 } else { // RANGE
1161 rbPages.setSelected(true);
1162 }
1163 tfRangeFrom.setValue(new Integer(min));
1164 tfRangeTo.setValue(new Integer(max));
1165 rbAll.setEnabled(prSupported);
1166 rbPages.setEnabled(prSupported);
1167 setupRangeWidgets();
1168 }
1169 }
1170
1171 private class CopiesPanel extends JPanel
1172 implements ActionListener, ChangeListener
1173 {
1174 private final String strTitle = getMsg("border.copies");
1175 private SpinnerNumberModel snModel;
1176 private JSpinner spinCopies;
1177 private JLabel lblCopies;
1178 private JCheckBox cbCollate;
1179 private boolean scSupported;
1180
1181 public CopiesPanel() {
1182 super();
1183
1184 GridBagLayout gridbag = new GridBagLayout();
1185 GridBagConstraints c = new GridBagConstraints();
1186
1187 setLayout(gridbag);
1188 setBorder(BorderFactory.createTitledBorder(strTitle));
1189
1190 c.fill = GridBagConstraints.HORIZONTAL;
1284 }
1285 SheetCollate sc = (SheetCollate)asCurrent.get(scCategory);
1286 if (sc == null) {
1287 sc = (SheetCollate)psCurrent.getDefaultAttributeValue(scCategory);
1288 if (sc == null) {
1289 sc = SheetCollate.UNCOLLATED;
1290 }
1291 }
1292 cbCollate.setSelected(sc == SheetCollate.COLLATED);
1293 updateCollateCB();
1294 }
1295 }
1296
1297
1298
1299
1300 /**
1301 * The "Page Setup" tab. Includes the controls for MediaSource/MediaTray,
1302 * OrientationRequested, and Sides.
1303 */
1304 private class PageSetupPanel extends JPanel {
1305
1306 private MediaPanel pnlMedia;
1307 private OrientationPanel pnlOrientation;
1308 private MarginsPanel pnlMargins;
1309
1310 public PageSetupPanel() {
1311 super();
1312
1313 GridBagLayout gridbag = new GridBagLayout();
1314 GridBagConstraints c = new GridBagConstraints();
1315
1316 setLayout(gridbag);
1317
1318 c.fill = GridBagConstraints.BOTH;
1319 c.insets = panelInsets;
1320 c.weightx = 1.0;
1321 c.weighty = 1.0;
1322
1323 c.gridwidth = GridBagConstraints.REMAINDER;
1325 addToGB(pnlMedia, this, gridbag, c);
1326
1327 pnlOrientation = new OrientationPanel();
1328 c.gridwidth = GridBagConstraints.RELATIVE;
1329 addToGB(pnlOrientation, this, gridbag, c);
1330
1331 pnlMargins = new MarginsPanel();
1332 pnlOrientation.addOrientationListener(pnlMargins);
1333 pnlMedia.addMediaListener(pnlMargins);
1334 c.gridwidth = GridBagConstraints.REMAINDER;
1335 addToGB(pnlMargins, this, gridbag, c);
1336 }
1337
1338 public void updateInfo() {
1339 pnlMedia.updateInfo();
1340 pnlOrientation.updateInfo();
1341 pnlMargins.updateInfo();
1342 }
1343 }
1344
1345 private class MarginsPanel extends JPanel
1346 implements ActionListener, FocusListener {
1347
1348 private final String strTitle = getMsg("border.margins");
1349 private JFormattedTextField leftMargin, rightMargin,
1350 topMargin, bottomMargin;
1351 private JLabel lblLeft, lblRight, lblTop, lblBottom;
1352 private int units = MediaPrintableArea.MM;
1353 // storage for the last margin values calculated, -ve is uninitialised
1354 private float lmVal = -1f,rmVal = -1f, tmVal = -1f, bmVal = -1f;
1355 // storage for margins as objects mapped into orientation for display
1356 private Float lmObj,rmObj,tmObj,bmObj;
1357
1358 public MarginsPanel() {
1359 super();
1360
1361 GridBagLayout gridbag = new GridBagLayout();
1362 GridBagConstraints c = new GridBagConstraints();
1363 c.fill = GridBagConstraints.HORIZONTAL;
1364 c.weightx = 1.0;
1855 tmp = lmObj;
1856 lmObj = bmObj;
1857 bmObj = rmObj;
1858 rmObj = tmObj;
1859 tmObj = tmp;
1860 } else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
1861 tmp = lmObj;
1862 lmObj = tmObj;
1863 tmObj = rmObj;
1864 rmObj = bmObj;
1865 bmObj = tmp;
1866 }
1867
1868 leftMargin.setValue(lmObj);
1869 rightMargin.setValue(rmObj);
1870 topMargin.setValue(tmObj);
1871 bottomMargin.setValue(bmObj);
1872 }
1873 }
1874
1875 private class MediaPanel extends JPanel implements ItemListener {
1876
1877 private final String strTitle = getMsg("border.media");
1878 private JLabel lblSize, lblSource;
1879 private JComboBox cbSize, cbSource;
1880 private Vector sizes = new Vector();
1881 private Vector sources = new Vector();
1882 private MarginsPanel pnlMargins = null;
1883
1884 public MediaPanel() {
1885 super();
1886
1887 GridBagLayout gridbag = new GridBagLayout();
1888 GridBagConstraints c = new GridBagConstraints();
1889
1890 setLayout(gridbag);
1891 setBorder(BorderFactory.createTitledBorder(strTitle));
1892
1893 cbSize = new JComboBox();
1894 cbSource = new JComboBox();
2089 asCurrent.add((MediaSizeName)sizes.get(selIndex));
2090 }
2091
2092 selIndex = cbSource.getSelectedIndex();
2093 if ((selIndex >= 1) && (selIndex < (sources.size()+1))) {
2094 MediaTray mt = (MediaTray)sources.get(selIndex-1);
2095 if (medium instanceof MediaTray) {
2096 asCurrent.add(mt);
2097 } else {
2098 asCurrent.add(new SunAlternateMedia(mt));
2099 }
2100 }
2101
2102
2103 }
2104 cbSize.addItemListener(this);
2105 cbSource.addItemListener(this);
2106 }
2107 }
2108
2109 private class OrientationPanel extends JPanel
2110 implements ActionListener
2111 {
2112 private final String strTitle = getMsg("border.orientation");
2113 private IconRadioButton rbPortrait, rbLandscape,
2114 rbRevPortrait, rbRevLandscape;
2115 private MarginsPanel pnlMargins = null;
2116
2117 public OrientationPanel() {
2118 super();
2119
2120 GridBagLayout gridbag = new GridBagLayout();
2121 GridBagConstraints c = new GridBagConstraints();
2122
2123 setLayout(gridbag);
2124 setBorder(BorderFactory.createTitledBorder(strTitle));
2125
2126 c.fill = GridBagConstraints.BOTH;
2127 c.insets = compInsets;
2128 c.weighty = 1.0;
2247 }
2248
2249 if (or == OrientationRequested.PORTRAIT) {
2250 rbPortrait.setSelected(true);
2251 } else if (or == OrientationRequested.LANDSCAPE) {
2252 rbLandscape.setSelected(true);
2253 } else if (or == OrientationRequested.REVERSE_PORTRAIT) {
2254 rbRevPortrait.setSelected(true);
2255 } else { // if (or == OrientationRequested.REVERSE_LANDSCAPE)
2256 rbRevLandscape.setSelected(true);
2257 }
2258 }
2259 }
2260
2261
2262
2263 /**
2264 * The "Appearance" tab. Includes the controls for Chromaticity,
2265 * PrintQuality, JobPriority, JobName, and other related job attributes.
2266 */
2267 private class AppearancePanel extends JPanel {
2268
2269 private ChromaticityPanel pnlChromaticity;
2270 private QualityPanel pnlQuality;
2271 private JobAttributesPanel pnlJobAttributes;
2272 private SidesPanel pnlSides;
2273
2274 public AppearancePanel() {
2275 super();
2276
2277 GridBagLayout gridbag = new GridBagLayout();
2278 GridBagConstraints c = new GridBagConstraints();
2279
2280 setLayout(gridbag);
2281
2282 c.fill = GridBagConstraints.BOTH;
2283 c.insets = panelInsets;
2284 c.weightx = 1.0;
2285 c.weighty = 1.0;
2286
2293 addToGB(pnlQuality, this, gridbag, c);
2294
2295 c.gridwidth = 1;
2296 pnlSides = new SidesPanel();
2297 addToGB(pnlSides, this, gridbag, c);
2298
2299 c.gridwidth = GridBagConstraints.REMAINDER;
2300 pnlJobAttributes = new JobAttributesPanel();
2301 addToGB(pnlJobAttributes, this, gridbag, c);
2302
2303 }
2304
2305 public void updateInfo() {
2306 pnlChromaticity.updateInfo();
2307 pnlQuality.updateInfo();
2308 pnlSides.updateInfo();
2309 pnlJobAttributes.updateInfo();
2310 }
2311 }
2312
2313 private class ChromaticityPanel extends JPanel
2314 implements ActionListener
2315 {
2316 private final String strTitle = getMsg("border.chromaticity");
2317 private JRadioButton rbMonochrome, rbColor;
2318
2319 public ChromaticityPanel() {
2320 super();
2321
2322 GridBagLayout gridbag = new GridBagLayout();
2323 GridBagConstraints c = new GridBagConstraints();
2324
2325 setLayout(gridbag);
2326 setBorder(BorderFactory.createTitledBorder(strTitle));
2327
2328 c.fill = GridBagConstraints.BOTH;
2329 c.gridwidth = GridBagConstraints.REMAINDER;
2330 c.weighty = 1.0;
2331
2332 ButtonGroup bg = new ButtonGroup();
2383
2384 rbMonochrome.setEnabled(monoSupported);
2385 rbColor.setEnabled(colorSupported);
2386
2387 Chromaticity ch = (Chromaticity)asCurrent.get(chCategory);
2388 if (ch == null) {
2389 ch = (Chromaticity)psCurrent.getDefaultAttributeValue(chCategory);
2390 if (ch == null) {
2391 ch = Chromaticity.MONOCHROME;
2392 }
2393 }
2394
2395 if (ch == Chromaticity.MONOCHROME) {
2396 rbMonochrome.setSelected(true);
2397 } else { // if (ch == Chromaticity.COLOR)
2398 rbColor.setSelected(true);
2399 }
2400 }
2401 }
2402
2403 private class QualityPanel extends JPanel
2404 implements ActionListener
2405 {
2406 private final String strTitle = getMsg("border.quality");
2407 private JRadioButton rbDraft, rbNormal, rbHigh;
2408
2409 public QualityPanel() {
2410 super();
2411
2412 GridBagLayout gridbag = new GridBagLayout();
2413 GridBagConstraints c = new GridBagConstraints();
2414
2415 setLayout(gridbag);
2416 setBorder(BorderFactory.createTitledBorder(strTitle));
2417
2418 c.fill = GridBagConstraints.BOTH;
2419 c.gridwidth = GridBagConstraints.REMAINDER;
2420 c.weighty = 1.0;
2421
2422 ButtonGroup bg = new ButtonGroup();
2484
2485 PrintQuality pq = (PrintQuality)asCurrent.get(pqCategory);
2486 if (pq == null) {
2487 pq = (PrintQuality)psCurrent.getDefaultAttributeValue(pqCategory);
2488 if (pq == null) {
2489 pq = PrintQuality.NORMAL;
2490 }
2491 }
2492
2493 if (pq == PrintQuality.DRAFT) {
2494 rbDraft.setSelected(true);
2495 } else if (pq == PrintQuality.NORMAL) {
2496 rbNormal.setSelected(true);
2497 } else { // if (pq == PrintQuality.HIGH)
2498 rbHigh.setSelected(true);
2499 }
2500 }
2501
2502
2503 }
2504 private class SidesPanel extends JPanel
2505 implements ActionListener
2506 {
2507 private final String strTitle = getMsg("border.sides");
2508 private IconRadioButton rbOneSide, rbTumble, rbDuplex;
2509
2510 public SidesPanel() {
2511 super();
2512
2513 GridBagLayout gridbag = new GridBagLayout();
2514 GridBagConstraints c = new GridBagConstraints();
2515
2516 setLayout(gridbag);
2517 setBorder(BorderFactory.createTitledBorder(strTitle));
2518
2519 c.fill = GridBagConstraints.BOTH;
2520 c.insets = compInsets;
2521 c.weighty = 1.0;
2522 c.gridwidth = GridBagConstraints.REMAINDER;
2523
2586
2587 Sides sd = (Sides)asCurrent.get(sdCategory);
2588 if (sd == null) {
2589 sd = (Sides)psCurrent.getDefaultAttributeValue(sdCategory);
2590 if (sd == null) {
2591 sd = Sides.ONE_SIDED;
2592 }
2593 }
2594
2595 if (sd == Sides.ONE_SIDED) {
2596 rbOneSide.setSelected(true);
2597 } else if (sd == Sides.TUMBLE) {
2598 rbTumble.setSelected(true);
2599 } else { // if (sd == Sides.DUPLEX)
2600 rbDuplex.setSelected(true);
2601 }
2602 }
2603 }
2604
2605
2606
2607 private class JobAttributesPanel extends JPanel
2608 implements ActionListener, ChangeListener, FocusListener
2609 {
2610 private final String strTitle = getMsg("border.jobattributes");
2611 private JLabel lblPriority, lblJobName, lblUserName;
2612 private JSpinner spinPriority;
2613 private SpinnerNumberModel snModel;
2614 private JCheckBox cbJobSheets;
2615 private JTextField tfJobName, tfUserName;
2616
2617 public JobAttributesPanel() {
2618 super();
2619
2620 GridBagLayout gridbag = new GridBagLayout();
2621 GridBagConstraints c = new GridBagConstraints();
2622
2623 setLayout(gridbag);
2624 setBorder(BorderFactory.createTitledBorder(strTitle));
2625
2626 c.fill = GridBagConstraints.NONE;
2774 RequestingUserName un = (RequestingUserName)asCurrent.get(unCategory);
2775 if (un == null) {
2776 un = (RequestingUserName)psCurrent.getDefaultAttributeValue(unCategory);
2777 if (un == null) {
2778 un = new RequestingUserName("", Locale.getDefault());
2779 }
2780 }
2781 tfUserName.setText(un.getValue());
2782 tfUserName.setEnabled(unSupported);
2783 lblUserName.setEnabled(unSupported);
2784 }
2785 }
2786
2787
2788
2789
2790 /**
2791 * A special widget that groups a JRadioButton with an associated icon,
2792 * placed to the left of the radio button.
2793 */
2794 private class IconRadioButton extends JPanel {
2795
2796 private JRadioButton rb;
2797 private JLabel lbl;
2798
2799 public IconRadioButton(String key, String img, boolean selected,
2800 ButtonGroup bg, ActionListener al)
2801 {
2802 super(new FlowLayout(FlowLayout.LEADING));
2803 final URL imgURL = getImageResource(img);
2804 Icon icon = (Icon)java.security.AccessController.doPrivileged(
2805 new java.security.PrivilegedAction() {
2806 public Object run() {
2807 Icon icon = new ImageIcon(imgURL);
2808 return icon;
2809 }
2810 });
2811 lbl = new JLabel(icon);
2812 add(lbl);
2813
2826
2827 public void setEnabled(boolean enabled) {
2828 rb.setEnabled(enabled);
2829 lbl.setEnabled(enabled);
2830 }
2831
2832 public boolean isSelected() {
2833 return rb.isSelected();
2834 }
2835
2836 public void setSelected(boolean selected) {
2837 rb.setSelected(selected);
2838 }
2839 }
2840
2841 /**
2842 * Similar in functionality to the default JFileChooser, except this
2843 * chooser will pop up a "Do you want to overwrite..." dialog if the
2844 * user selects a file that already exists.
2845 */
2846 private class ValidatingFileChooser extends JFileChooser {
2847 public void approveSelection() {
2848 File selected = getSelectedFile();
2849 boolean exists;
2850
2851 try {
2852 exists = selected.exists();
2853 } catch (SecurityException e) {
2854 exists = false;
2855 }
2856
2857 if (exists) {
2858 int val;
2859 val = JOptionPane.showConfirmDialog(this,
2860 getMsg("dialog.overwrite"),
2861 getMsg("dialog.owtitle"),
2862 JOptionPane.YES_NO_OPTION);
2863 if (val != JOptionPane.YES_OPTION) {
2864 return;
2865 }
|
1 /*
2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
64 import javax.swing.border.EmptyBorder;
65 import javax.swing.border.TitledBorder;
66 import javax.swing.event.ChangeEvent;
67 import javax.swing.event.ChangeListener;
68 import javax.swing.event.DocumentEvent;
69 import javax.swing.event.DocumentListener;
70 import javax.swing.event.PopupMenuEvent;
71 import javax.swing.event.PopupMenuListener;
72 import javax.swing.text.NumberFormatter;
73 import sun.print.SunPageSelection;
74 import java.awt.event.KeyEvent;
75 import java.net.URISyntaxException;
76 import java.lang.reflect.Field;
77
78
79 /**
80 * A class which implements a cross-platform print dialog.
81 *
82 * @author Chris Campbell
83 */
84 @SuppressWarnings("serial") // Superclass is not serializable across versions
85 public class ServiceDialog extends JDialog implements ActionListener {
86
87 /**
88 * Waiting print status (user response pending).
89 */
90 public final static int WAITING = 0;
91
92 /**
93 * Approve print status (user activated "Print" or "OK").
94 */
95 public final static int APPROVE = 1;
96
97 /**
98 * Cancel print status (user activated "Cancel");
99 */
100 public final static int CANCEL = 2;
101
102 private static final String strBundle = "sun.print.resources.serviceui";
103 private static final Insets panelInsets = new Insets(6, 6, 6, 6);
104 private static final Insets compInsets = new Insets(3, 6, 3, 6);
291 handleEscKey(btnCancel);
292 pnlSouth.add(btnCancel);
293 c.add(pnlSouth, BorderLayout.SOUTH);
294
295 addWindowListener(new WindowAdapter() {
296 public void windowClosing(WindowEvent event) {
297 dispose(CANCEL);
298 }
299 });
300
301 getAccessibleContext().setAccessibleDescription(getMsg("dialog.pstitle"));
302 setResizable(false);
303 setLocation(x, y);
304 pack();
305 }
306
307 /**
308 * Performs Cancel when Esc key is pressed.
309 */
310 private void handleEscKey(JButton btnCancel) {
311 @SuppressWarnings("serial") // anonymous class
312 Action cancelKeyAction = new AbstractAction() {
313 public void actionPerformed(ActionEvent e) {
314 dispose(CANCEL);
315 }
316 };
317 KeyStroke cancelKeyStroke =
318 KeyStroke.getKeyStroke((char)KeyEvent.VK_ESCAPE, 0);
319 InputMap inputMap =
320 btnCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
321 ActionMap actionMap = btnCancel.getActionMap();
322
323 if (inputMap != null && actionMap != null) {
324 inputMap.put(cancelKeyStroke, "cancel");
325 actionMap.put("cancel", cancelKeyAction);
326 }
327 }
328
329
330 /**
331 * Returns the current status of the dialog (whether the user has selected
641 cont.add(comp);
642 }
643
644 /**
645 * Adds the AbstractButton to both the given ButtonGroup and Container
646 */
647 private static void addToBG(AbstractButton button, Container cont,
648 ButtonGroup bg)
649 {
650 bg.add(button);
651 cont.add(button);
652 }
653
654
655
656
657 /**
658 * The "General" tab. Includes the controls for PrintService,
659 * PageRange, and Copies/Collate.
660 */
661 @SuppressWarnings("serial") // Superclass is not serializable across versions
662 private class GeneralPanel extends JPanel {
663
664 private PrintServicePanel pnlPrintService;
665 private PrintRangePanel pnlPrintRange;
666 private CopiesPanel pnlCopies;
667
668 public GeneralPanel() {
669 super();
670
671 GridBagLayout gridbag = new GridBagLayout();
672 GridBagConstraints c = new GridBagConstraints();
673
674 setLayout(gridbag);
675
676 c.fill = GridBagConstraints.BOTH;
677 c.insets = panelInsets;
678 c.weightx = 1.0;
679 c.weighty = 1.0;
680
681 c.gridwidth = GridBagConstraints.REMAINDER;
685 c.gridwidth = GridBagConstraints.RELATIVE;
686 pnlPrintRange = new PrintRangePanel();
687 addToGB(pnlPrintRange, this, gridbag, c);
688
689 c.gridwidth = GridBagConstraints.REMAINDER;
690 pnlCopies = new CopiesPanel();
691 addToGB(pnlCopies, this, gridbag, c);
692 }
693
694 public boolean isPrintToFileRequested() {
695 return (pnlPrintService.isPrintToFileSelected());
696 }
697
698 public void updateInfo() {
699 pnlPrintService.updateInfo();
700 pnlPrintRange.updateInfo();
701 pnlCopies.updateInfo();
702 }
703 }
704
705 @SuppressWarnings("serial") // Superclass is not serializable across versions
706 private class PrintServicePanel extends JPanel
707 implements ActionListener, ItemListener, PopupMenuListener
708 {
709 private final String strTitle = getMsg("border.printservice");
710 private FilePermission printToFilePermission;
711 private JButton btnProperties;
712 private JCheckBox cbPrintToFile;
713 private JComboBox cbName;
714 private JLabel lblType, lblStatus, lblInfo;
715 private ServiceUIFactory uiFactory;
716 private boolean changedService = false;
717 private boolean filePermission;
718
719 public PrintServicePanel() {
720 super();
721
722 uiFactory = psCurrent.getServiceUIFactory();
723
724 GridBagLayout gridbag = new GridBagLayout();
725 GridBagConstraints c = new GridBagConstraints();
943 && dstSupported);
944
945 // setup PrintService information widgets
946 Attribute type = psCurrent.getAttribute(PrinterMakeAndModel.class);
947 if (type != null) {
948 lblType.setText(type.toString());
949 }
950 Attribute status =
951 psCurrent.getAttribute(PrinterIsAcceptingJobs.class);
952 if (status != null) {
953 lblStatus.setText(getMsg(status.toString()));
954 }
955 Attribute info = psCurrent.getAttribute(PrinterInfo.class);
956 if (info != null) {
957 lblInfo.setText(info.toString());
958 }
959 btnProperties.setEnabled(uiFactory != null);
960 }
961 }
962
963 @SuppressWarnings("serial") // Superclass is not serializable across versions
964 private class PrintRangePanel extends JPanel
965 implements ActionListener, FocusListener
966 {
967 private final String strTitle = getMsg("border.printrange");
968 private final PageRanges prAll = new PageRanges(1, Integer.MAX_VALUE);
969 private JRadioButton rbAll, rbPages, rbSelect;
970 private JFormattedTextField tfRangeFrom, tfRangeTo;
971 private JLabel lblRangeTo;
972 private boolean prSupported;
973
974 public PrintRangePanel() {
975 super();
976
977 GridBagLayout gridbag = new GridBagLayout();
978 GridBagConstraints c = new GridBagConstraints();
979
980 setLayout(gridbag);
981 setBorder(BorderFactory.createTitledBorder(strTitle));
982
983 c.fill = GridBagConstraints.BOTH;
1156
1157 if (select == SunPageSelection.ALL) {
1158 rbAll.setSelected(true);
1159 } else if (select == SunPageSelection.SELECTION) {
1160 // Comment this for now - rbSelect is not initialized
1161 // because Selection button is not added.
1162 // See PrintRangePanel above.
1163
1164 //rbSelect.setSelected(true);
1165 } else { // RANGE
1166 rbPages.setSelected(true);
1167 }
1168 tfRangeFrom.setValue(new Integer(min));
1169 tfRangeTo.setValue(new Integer(max));
1170 rbAll.setEnabled(prSupported);
1171 rbPages.setEnabled(prSupported);
1172 setupRangeWidgets();
1173 }
1174 }
1175
1176 @SuppressWarnings("serial") // Superclass is not serializable across versions
1177 private class CopiesPanel extends JPanel
1178 implements ActionListener, ChangeListener
1179 {
1180 private final String strTitle = getMsg("border.copies");
1181 private SpinnerNumberModel snModel;
1182 private JSpinner spinCopies;
1183 private JLabel lblCopies;
1184 private JCheckBox cbCollate;
1185 private boolean scSupported;
1186
1187 public CopiesPanel() {
1188 super();
1189
1190 GridBagLayout gridbag = new GridBagLayout();
1191 GridBagConstraints c = new GridBagConstraints();
1192
1193 setLayout(gridbag);
1194 setBorder(BorderFactory.createTitledBorder(strTitle));
1195
1196 c.fill = GridBagConstraints.HORIZONTAL;
1290 }
1291 SheetCollate sc = (SheetCollate)asCurrent.get(scCategory);
1292 if (sc == null) {
1293 sc = (SheetCollate)psCurrent.getDefaultAttributeValue(scCategory);
1294 if (sc == null) {
1295 sc = SheetCollate.UNCOLLATED;
1296 }
1297 }
1298 cbCollate.setSelected(sc == SheetCollate.COLLATED);
1299 updateCollateCB();
1300 }
1301 }
1302
1303
1304
1305
1306 /**
1307 * The "Page Setup" tab. Includes the controls for MediaSource/MediaTray,
1308 * OrientationRequested, and Sides.
1309 */
1310 @SuppressWarnings("serial") // Superclass is not serializable across versions
1311 private class PageSetupPanel extends JPanel {
1312
1313 private MediaPanel pnlMedia;
1314 private OrientationPanel pnlOrientation;
1315 private MarginsPanel pnlMargins;
1316
1317 public PageSetupPanel() {
1318 super();
1319
1320 GridBagLayout gridbag = new GridBagLayout();
1321 GridBagConstraints c = new GridBagConstraints();
1322
1323 setLayout(gridbag);
1324
1325 c.fill = GridBagConstraints.BOTH;
1326 c.insets = panelInsets;
1327 c.weightx = 1.0;
1328 c.weighty = 1.0;
1329
1330 c.gridwidth = GridBagConstraints.REMAINDER;
1332 addToGB(pnlMedia, this, gridbag, c);
1333
1334 pnlOrientation = new OrientationPanel();
1335 c.gridwidth = GridBagConstraints.RELATIVE;
1336 addToGB(pnlOrientation, this, gridbag, c);
1337
1338 pnlMargins = new MarginsPanel();
1339 pnlOrientation.addOrientationListener(pnlMargins);
1340 pnlMedia.addMediaListener(pnlMargins);
1341 c.gridwidth = GridBagConstraints.REMAINDER;
1342 addToGB(pnlMargins, this, gridbag, c);
1343 }
1344
1345 public void updateInfo() {
1346 pnlMedia.updateInfo();
1347 pnlOrientation.updateInfo();
1348 pnlMargins.updateInfo();
1349 }
1350 }
1351
1352 @SuppressWarnings("serial") // Superclass is not serializable across versions
1353 private class MarginsPanel extends JPanel
1354 implements ActionListener, FocusListener {
1355
1356 private final String strTitle = getMsg("border.margins");
1357 private JFormattedTextField leftMargin, rightMargin,
1358 topMargin, bottomMargin;
1359 private JLabel lblLeft, lblRight, lblTop, lblBottom;
1360 private int units = MediaPrintableArea.MM;
1361 // storage for the last margin values calculated, -ve is uninitialised
1362 private float lmVal = -1f,rmVal = -1f, tmVal = -1f, bmVal = -1f;
1363 // storage for margins as objects mapped into orientation for display
1364 private Float lmObj,rmObj,tmObj,bmObj;
1365
1366 public MarginsPanel() {
1367 super();
1368
1369 GridBagLayout gridbag = new GridBagLayout();
1370 GridBagConstraints c = new GridBagConstraints();
1371 c.fill = GridBagConstraints.HORIZONTAL;
1372 c.weightx = 1.0;
1863 tmp = lmObj;
1864 lmObj = bmObj;
1865 bmObj = rmObj;
1866 rmObj = tmObj;
1867 tmObj = tmp;
1868 } else if (or == OrientationRequested.REVERSE_LANDSCAPE) {
1869 tmp = lmObj;
1870 lmObj = tmObj;
1871 tmObj = rmObj;
1872 rmObj = bmObj;
1873 bmObj = tmp;
1874 }
1875
1876 leftMargin.setValue(lmObj);
1877 rightMargin.setValue(rmObj);
1878 topMargin.setValue(tmObj);
1879 bottomMargin.setValue(bmObj);
1880 }
1881 }
1882
1883 @SuppressWarnings("serial") // Superclass is not serializable across versions
1884 private class MediaPanel extends JPanel implements ItemListener {
1885
1886 private final String strTitle = getMsg("border.media");
1887 private JLabel lblSize, lblSource;
1888 private JComboBox cbSize, cbSource;
1889 private Vector sizes = new Vector();
1890 private Vector sources = new Vector();
1891 private MarginsPanel pnlMargins = null;
1892
1893 public MediaPanel() {
1894 super();
1895
1896 GridBagLayout gridbag = new GridBagLayout();
1897 GridBagConstraints c = new GridBagConstraints();
1898
1899 setLayout(gridbag);
1900 setBorder(BorderFactory.createTitledBorder(strTitle));
1901
1902 cbSize = new JComboBox();
1903 cbSource = new JComboBox();
2098 asCurrent.add((MediaSizeName)sizes.get(selIndex));
2099 }
2100
2101 selIndex = cbSource.getSelectedIndex();
2102 if ((selIndex >= 1) && (selIndex < (sources.size()+1))) {
2103 MediaTray mt = (MediaTray)sources.get(selIndex-1);
2104 if (medium instanceof MediaTray) {
2105 asCurrent.add(mt);
2106 } else {
2107 asCurrent.add(new SunAlternateMedia(mt));
2108 }
2109 }
2110
2111
2112 }
2113 cbSize.addItemListener(this);
2114 cbSource.addItemListener(this);
2115 }
2116 }
2117
2118 @SuppressWarnings("serial") // Superclass is not serializable across versions
2119 private class OrientationPanel extends JPanel
2120 implements ActionListener
2121 {
2122 private final String strTitle = getMsg("border.orientation");
2123 private IconRadioButton rbPortrait, rbLandscape,
2124 rbRevPortrait, rbRevLandscape;
2125 private MarginsPanel pnlMargins = null;
2126
2127 public OrientationPanel() {
2128 super();
2129
2130 GridBagLayout gridbag = new GridBagLayout();
2131 GridBagConstraints c = new GridBagConstraints();
2132
2133 setLayout(gridbag);
2134 setBorder(BorderFactory.createTitledBorder(strTitle));
2135
2136 c.fill = GridBagConstraints.BOTH;
2137 c.insets = compInsets;
2138 c.weighty = 1.0;
2257 }
2258
2259 if (or == OrientationRequested.PORTRAIT) {
2260 rbPortrait.setSelected(true);
2261 } else if (or == OrientationRequested.LANDSCAPE) {
2262 rbLandscape.setSelected(true);
2263 } else if (or == OrientationRequested.REVERSE_PORTRAIT) {
2264 rbRevPortrait.setSelected(true);
2265 } else { // if (or == OrientationRequested.REVERSE_LANDSCAPE)
2266 rbRevLandscape.setSelected(true);
2267 }
2268 }
2269 }
2270
2271
2272
2273 /**
2274 * The "Appearance" tab. Includes the controls for Chromaticity,
2275 * PrintQuality, JobPriority, JobName, and other related job attributes.
2276 */
2277 @SuppressWarnings("serial") // Superclass is not serializable across versions
2278 private class AppearancePanel extends JPanel {
2279
2280 private ChromaticityPanel pnlChromaticity;
2281 private QualityPanel pnlQuality;
2282 private JobAttributesPanel pnlJobAttributes;
2283 private SidesPanel pnlSides;
2284
2285 public AppearancePanel() {
2286 super();
2287
2288 GridBagLayout gridbag = new GridBagLayout();
2289 GridBagConstraints c = new GridBagConstraints();
2290
2291 setLayout(gridbag);
2292
2293 c.fill = GridBagConstraints.BOTH;
2294 c.insets = panelInsets;
2295 c.weightx = 1.0;
2296 c.weighty = 1.0;
2297
2304 addToGB(pnlQuality, this, gridbag, c);
2305
2306 c.gridwidth = 1;
2307 pnlSides = new SidesPanel();
2308 addToGB(pnlSides, this, gridbag, c);
2309
2310 c.gridwidth = GridBagConstraints.REMAINDER;
2311 pnlJobAttributes = new JobAttributesPanel();
2312 addToGB(pnlJobAttributes, this, gridbag, c);
2313
2314 }
2315
2316 public void updateInfo() {
2317 pnlChromaticity.updateInfo();
2318 pnlQuality.updateInfo();
2319 pnlSides.updateInfo();
2320 pnlJobAttributes.updateInfo();
2321 }
2322 }
2323
2324 @SuppressWarnings("serial") // Superclass is not serializable across versions
2325 private class ChromaticityPanel extends JPanel
2326 implements ActionListener
2327 {
2328 private final String strTitle = getMsg("border.chromaticity");
2329 private JRadioButton rbMonochrome, rbColor;
2330
2331 public ChromaticityPanel() {
2332 super();
2333
2334 GridBagLayout gridbag = new GridBagLayout();
2335 GridBagConstraints c = new GridBagConstraints();
2336
2337 setLayout(gridbag);
2338 setBorder(BorderFactory.createTitledBorder(strTitle));
2339
2340 c.fill = GridBagConstraints.BOTH;
2341 c.gridwidth = GridBagConstraints.REMAINDER;
2342 c.weighty = 1.0;
2343
2344 ButtonGroup bg = new ButtonGroup();
2395
2396 rbMonochrome.setEnabled(monoSupported);
2397 rbColor.setEnabled(colorSupported);
2398
2399 Chromaticity ch = (Chromaticity)asCurrent.get(chCategory);
2400 if (ch == null) {
2401 ch = (Chromaticity)psCurrent.getDefaultAttributeValue(chCategory);
2402 if (ch == null) {
2403 ch = Chromaticity.MONOCHROME;
2404 }
2405 }
2406
2407 if (ch == Chromaticity.MONOCHROME) {
2408 rbMonochrome.setSelected(true);
2409 } else { // if (ch == Chromaticity.COLOR)
2410 rbColor.setSelected(true);
2411 }
2412 }
2413 }
2414
2415 @SuppressWarnings("serial") // Superclass is not serializable across versions
2416 private class QualityPanel extends JPanel
2417 implements ActionListener
2418 {
2419 private final String strTitle = getMsg("border.quality");
2420 private JRadioButton rbDraft, rbNormal, rbHigh;
2421
2422 public QualityPanel() {
2423 super();
2424
2425 GridBagLayout gridbag = new GridBagLayout();
2426 GridBagConstraints c = new GridBagConstraints();
2427
2428 setLayout(gridbag);
2429 setBorder(BorderFactory.createTitledBorder(strTitle));
2430
2431 c.fill = GridBagConstraints.BOTH;
2432 c.gridwidth = GridBagConstraints.REMAINDER;
2433 c.weighty = 1.0;
2434
2435 ButtonGroup bg = new ButtonGroup();
2497
2498 PrintQuality pq = (PrintQuality)asCurrent.get(pqCategory);
2499 if (pq == null) {
2500 pq = (PrintQuality)psCurrent.getDefaultAttributeValue(pqCategory);
2501 if (pq == null) {
2502 pq = PrintQuality.NORMAL;
2503 }
2504 }
2505
2506 if (pq == PrintQuality.DRAFT) {
2507 rbDraft.setSelected(true);
2508 } else if (pq == PrintQuality.NORMAL) {
2509 rbNormal.setSelected(true);
2510 } else { // if (pq == PrintQuality.HIGH)
2511 rbHigh.setSelected(true);
2512 }
2513 }
2514
2515
2516 }
2517
2518 @SuppressWarnings("serial") // Superclass is not serializable across versions
2519 private class SidesPanel extends JPanel
2520 implements ActionListener
2521 {
2522 private final String strTitle = getMsg("border.sides");
2523 private IconRadioButton rbOneSide, rbTumble, rbDuplex;
2524
2525 public SidesPanel() {
2526 super();
2527
2528 GridBagLayout gridbag = new GridBagLayout();
2529 GridBagConstraints c = new GridBagConstraints();
2530
2531 setLayout(gridbag);
2532 setBorder(BorderFactory.createTitledBorder(strTitle));
2533
2534 c.fill = GridBagConstraints.BOTH;
2535 c.insets = compInsets;
2536 c.weighty = 1.0;
2537 c.gridwidth = GridBagConstraints.REMAINDER;
2538
2601
2602 Sides sd = (Sides)asCurrent.get(sdCategory);
2603 if (sd == null) {
2604 sd = (Sides)psCurrent.getDefaultAttributeValue(sdCategory);
2605 if (sd == null) {
2606 sd = Sides.ONE_SIDED;
2607 }
2608 }
2609
2610 if (sd == Sides.ONE_SIDED) {
2611 rbOneSide.setSelected(true);
2612 } else if (sd == Sides.TUMBLE) {
2613 rbTumble.setSelected(true);
2614 } else { // if (sd == Sides.DUPLEX)
2615 rbDuplex.setSelected(true);
2616 }
2617 }
2618 }
2619
2620
2621 @SuppressWarnings("serial") // Superclass is not serializable across versions
2622 private class JobAttributesPanel extends JPanel
2623 implements ActionListener, ChangeListener, FocusListener
2624 {
2625 private final String strTitle = getMsg("border.jobattributes");
2626 private JLabel lblPriority, lblJobName, lblUserName;
2627 private JSpinner spinPriority;
2628 private SpinnerNumberModel snModel;
2629 private JCheckBox cbJobSheets;
2630 private JTextField tfJobName, tfUserName;
2631
2632 public JobAttributesPanel() {
2633 super();
2634
2635 GridBagLayout gridbag = new GridBagLayout();
2636 GridBagConstraints c = new GridBagConstraints();
2637
2638 setLayout(gridbag);
2639 setBorder(BorderFactory.createTitledBorder(strTitle));
2640
2641 c.fill = GridBagConstraints.NONE;
2789 RequestingUserName un = (RequestingUserName)asCurrent.get(unCategory);
2790 if (un == null) {
2791 un = (RequestingUserName)psCurrent.getDefaultAttributeValue(unCategory);
2792 if (un == null) {
2793 un = new RequestingUserName("", Locale.getDefault());
2794 }
2795 }
2796 tfUserName.setText(un.getValue());
2797 tfUserName.setEnabled(unSupported);
2798 lblUserName.setEnabled(unSupported);
2799 }
2800 }
2801
2802
2803
2804
2805 /**
2806 * A special widget that groups a JRadioButton with an associated icon,
2807 * placed to the left of the radio button.
2808 */
2809 @SuppressWarnings("serial") // Superclass is not serializable across versions
2810 private class IconRadioButton extends JPanel {
2811
2812 private JRadioButton rb;
2813 private JLabel lbl;
2814
2815 public IconRadioButton(String key, String img, boolean selected,
2816 ButtonGroup bg, ActionListener al)
2817 {
2818 super(new FlowLayout(FlowLayout.LEADING));
2819 final URL imgURL = getImageResource(img);
2820 Icon icon = (Icon)java.security.AccessController.doPrivileged(
2821 new java.security.PrivilegedAction() {
2822 public Object run() {
2823 Icon icon = new ImageIcon(imgURL);
2824 return icon;
2825 }
2826 });
2827 lbl = new JLabel(icon);
2828 add(lbl);
2829
2842
2843 public void setEnabled(boolean enabled) {
2844 rb.setEnabled(enabled);
2845 lbl.setEnabled(enabled);
2846 }
2847
2848 public boolean isSelected() {
2849 return rb.isSelected();
2850 }
2851
2852 public void setSelected(boolean selected) {
2853 rb.setSelected(selected);
2854 }
2855 }
2856
2857 /**
2858 * Similar in functionality to the default JFileChooser, except this
2859 * chooser will pop up a "Do you want to overwrite..." dialog if the
2860 * user selects a file that already exists.
2861 */
2862 @SuppressWarnings("serial") // JDK implementation class
2863 private class ValidatingFileChooser extends JFileChooser {
2864 public void approveSelection() {
2865 File selected = getSelectedFile();
2866 boolean exists;
2867
2868 try {
2869 exists = selected.exists();
2870 } catch (SecurityException e) {
2871 exists = false;
2872 }
2873
2874 if (exists) {
2875 int val;
2876 val = JOptionPane.showConfirmDialog(this,
2877 getMsg("dialog.overwrite"),
2878 getMsg("dialog.owtitle"),
2879 JOptionPane.YES_NO_OPTION);
2880 if (val != JOptionPane.YES_OPTION) {
2881 return;
2882 }
|