|
What this is
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.pdf;
import java.io.File;
import java.util.ResourceBundle;
import javax.swing.JFileChooser;
import org.openide.util.NbBundle;
/** Simple panel for a dialog asking users to choose a PDF viewer.
* Offers a file chooser.
* @author Jesse Glick
*/
public class ReconfigureReaderPanel extends javax.swing.JPanel {
private Settings settings;
private final File defaultViewer;
private ResourceBundle bundle = NbBundle.getBundle (ReconfigureReaderPanel.class);
public ReconfigureReaderPanel (File defaultViewer, String exceptionMessage) {
settings = Settings.getDefault ();
this.defaultViewer = defaultViewer;
initComponents ();
initAccessibility ();
}
private void initAccessibility() {
this.getAccessibleContext().setAccessibleDescription(bundle.getString ("LBL_reconfigure"));
viewerField.getAccessibleContext().setAccessibleDescription(bundle.getString ("ACS_Field"));
chooseButton.getAccessibleContext().setAccessibleDescription(bundle.getString ("ACS_LBL_choose"));
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
java.awt.GridBagConstraints gridBagConstraints;
topLabel = new javax.swing.JLabel();
currentViewerLabel = new javax.swing.JLabel();
viewerField = new javax.swing.JTextField();
chooseButton = new javax.swing.JButton();
setLayout(new java.awt.GridBagLayout());
topLabel.setText(bundle.getString ("LBL_reconfigure"));
topLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 11);
add(topLabel, gridBagConstraints);
currentViewerLabel.setText(bundle.getString ("LBL_current_viewer"));
currentViewerLabel.setLabelFor(viewerField);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 12);
add(currentViewerLabel, gridBagConstraints);
viewerField.setText(settings.getPDFViewer() != null ? settings.getPDFViewer().getPath() : PDFOpenSupport.FALLBACK_VIEWER_NAME);
viewerField.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
viewerFieldFocusGained(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0);
add(viewerField, gridBagConstraints);
chooseButton.setMnemonic((bundle.getString ("LBL_choose_mnem")).charAt(0));
chooseButton.setText(bundle.getString ("LBL_choose"));
chooseButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chooseButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 12, 11);
add(chooseButton, gridBagConstraints);
}//GEN-END:initComponents
// accessibility
private void viewerFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_viewerFieldFocusGained
viewerField.selectAll();
}//GEN-LAST:event_viewerFieldFocusGained
private void chooseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseButtonActionPerformed
File dir = defaultViewer.getParentFile();
JFileChooser chooser = (dir != null)
? new JFileChooser(dir)
: new JFileChooser();
String chooserTitle = bundle.getString("LBL_select_viewer"); //NOI18N
if (chooser.showDialog (this, chooserTitle)
== JFileChooser.APPROVE_OPTION) {
viewerField.setText(chooser.getSelectedFile().getPath());
}
}//GEN-LAST:event_chooseButtonActionPerformed
/**
*/
File getSelectedFile() {
return new File(viewerField.getText().trim());
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton chooseButton;
private javax.swing.JLabel currentViewerLabel;
private javax.swing.JLabel topLabel;
private javax.swing.JTextField viewerField;
// End of variables declaration//GEN-END:variables
}
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.