1 19 20 package org.netbeans.modules.pdf; 21 22 import java.io.File ; 23 import java.util.ResourceBundle ; 24 import javax.swing.JFileChooser ; 25 26 import org.openide.util.NbBundle; 27 28 32 public class ReconfigureReaderPanel extends javax.swing.JPanel { 33 34 private Settings settings; 35 private final File defaultViewer; 36 private ResourceBundle bundle = NbBundle.getBundle (ReconfigureReaderPanel.class); 37 38 public ReconfigureReaderPanel (File defaultViewer, String 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 56 private void initComponents() { 58 java.awt.GridBagConstraints gridBagConstraints; 59 60 topLabel = new javax.swing.JLabel (); 61 currentViewerLabel = new javax.swing.JLabel (); 62 viewerField = new javax.swing.JTextField (); 63 chooseButton = new javax.swing.JButton (); 64 65 setLayout(new java.awt.GridBagLayout ()); 66 67 topLabel.setText(bundle.getString ("LBL_reconfigure")); 68 topLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 69 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 79 gridBagConstraints.gridx = 0; 80 gridBagConstraints.gridy = 1; 81 gridBagConstraints.insets = new java.awt.Insets (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 () { 86 public void focusGained(java.awt.event.FocusEvent evt) { 87 viewerFieldFocusGained(evt); 88 } 89 }); 90 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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")); chooseButton.addActionListener(new java.awt.event.ActionListener () { 100 public void actionPerformed(java.awt.event.ActionEvent evt) { 101 chooseButtonActionPerformed(evt); 102 } 103 }); 104 gridBagConstraints = new java.awt.GridBagConstraints (); 105 gridBagConstraints.gridx = 2; 106 gridBagConstraints.gridy = 1; 107 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 108 gridBagConstraints.insets = new java.awt.Insets (0, 5, 12, 11); 109 add(chooseButton, gridBagConstraints); 110 } 112 private void viewerFieldFocusGained(java.awt.event.FocusEvent evt) { viewerField.selectAll(); 115 } 117 private void chooseButtonActionPerformed(java.awt.event.ActionEvent evt) { File dir = defaultViewer.getParentFile(); 119 JFileChooser chooser = (dir != null) 120 ? new JFileChooser (dir) 121 : new JFileChooser (); 122 String chooserTitle = bundle.getString("LBL_select_viewer"); if (chooser.showDialog (this, chooserTitle) 124 == JFileChooser.APPROVE_OPTION) { 125 viewerField.setText(chooser.getSelectedFile().getPath()); 126 } 127 } 129 131 File getSelectedFile() { 132 return new File (viewerField.getText().trim()); 133 } 134 135 private javax.swing.JButton chooseButton; 137 private javax.swing.JLabel currentViewerLabel; 138 private javax.swing.JLabel topLabel; 139 private javax.swing.JTextField viewerField; 140 142 } 143 | Popular Tags |