KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > pdf > ReconfigureReaderPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.pdf;
21
22 import java.io.File JavaDoc;
23 import java.util.ResourceBundle JavaDoc;
24 import javax.swing.JFileChooser JavaDoc;
25
26 import org.openide.util.NbBundle;
27
28 /** Simple panel for a dialog asking users to choose a PDF viewer.
29  * Offers a file chooser.
30  * @author Jesse Glick
31  */

32 public class ReconfigureReaderPanel extends javax.swing.JPanel JavaDoc {
33
34     private Settings settings;
35     private final File JavaDoc defaultViewer;
36     private ResourceBundle JavaDoc bundle = NbBundle.getBundle (ReconfigureReaderPanel.class);
37
38     public ReconfigureReaderPanel (File JavaDoc defaultViewer, String JavaDoc exceptionMessage) {
39         settings = Settings.getDefault ();
40         this.defaultViewer = defaultViewer;
41         initComponents ();
42         initAccessibility ();
43     }
44
45     private void initAccessibility() {
46         this.getAccessibleContext().setAccessibleDescription(bundle.getString ("LBL_reconfigure"));
47         viewerField.getAccessibleContext().setAccessibleDescription(bundle.getString ("ACS_Field"));
48         chooseButton.getAccessibleContext().setAccessibleDescription(bundle.getString ("ACS_LBL_choose"));
49     }
50     
51     /** This method is called from within the constructor to
52      * initialize the form.
53      * WARNING: Do NOT modify this code. The content of this method is
54      * always regenerated by the Form Editor.
55      */

56     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
57
private void initComponents() {
58         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
59
60         topLabel = new javax.swing.JLabel JavaDoc();
61         currentViewerLabel = new javax.swing.JLabel JavaDoc();
62         viewerField = new javax.swing.JTextField JavaDoc();
63         chooseButton = new javax.swing.JButton JavaDoc();
64
65         setLayout(new java.awt.GridBagLayout JavaDoc());
66
67         topLabel.setText(bundle.getString ("LBL_reconfigure"));
68         topLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
69         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
70         gridBagConstraints.gridwidth = 3;
71         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
72         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
73         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 11);
74         add(topLabel, gridBagConstraints);
75
76         currentViewerLabel.setText(bundle.getString ("LBL_current_viewer"));
77         currentViewerLabel.setLabelFor(viewerField);
78         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
79         gridBagConstraints.gridx = 0;
80         gridBagConstraints.gridy = 1;
81         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 12);
82         add(currentViewerLabel, gridBagConstraints);
83
84         viewerField.setText(settings.getPDFViewer() != null ? settings.getPDFViewer().getPath() : PDFOpenSupport.FALLBACK_VIEWER_NAME);
85         viewerField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
86             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
87                 viewerFieldFocusGained(evt);
88             }
89         });
90         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
91         gridBagConstraints.gridx = 1;
92         gridBagConstraints.gridy = 1;
93         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
94         gridBagConstraints.weightx = 1.0;
95         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
96         add(viewerField, gridBagConstraints);
97
98         org.openide.awt.Mnemonics.setLocalizedText(chooseButton, org.openide.util.NbBundle.getMessage(ReconfigureReaderPanel.class, "LBL_choose")); // NOI18N
99
chooseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
100             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
101                 chooseButtonActionPerformed(evt);
102             }
103         });
104         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
105         gridBagConstraints.gridx = 2;
106         gridBagConstraints.gridy = 1;
107         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
108         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 12, 11);
109         add(chooseButton, gridBagConstraints);
110     }// </editor-fold>//GEN-END:initComponents
111

112     // accessibility
113
private void viewerFieldFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_viewerFieldFocusGained
114
viewerField.selectAll();
115     }//GEN-LAST:event_viewerFieldFocusGained
116

117     private void chooseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_chooseButtonActionPerformed
118
File JavaDoc dir = defaultViewer.getParentFile();
119         JFileChooser JavaDoc chooser = (dir != null)
120                                ? new JFileChooser JavaDoc(dir)
121                                : new JFileChooser JavaDoc();
122         String JavaDoc chooserTitle = bundle.getString("LBL_select_viewer"); //NOI18N
123
if (chooser.showDialog (this, chooserTitle)
124                 == JFileChooser.APPROVE_OPTION) {
125             viewerField.setText(chooser.getSelectedFile().getPath());
126         }
127     }//GEN-LAST:event_chooseButtonActionPerformed
128

129     /**
130      */

131     File JavaDoc getSelectedFile() {
132         return new File JavaDoc(viewerField.getText().trim());
133     }
134
135     // Variables declaration - do not modify//GEN-BEGIN:variables
136
private javax.swing.JButton JavaDoc chooseButton;
137     private javax.swing.JLabel JavaDoc currentViewerLabel;
138     private javax.swing.JLabel JavaDoc topLabel;
139     private javax.swing.JTextField JavaDoc viewerField;
140     // End of variables declaration//GEN-END:variables
141

142 }
143
Popular Tags