All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.netbeans.modules.pdf.SetCommandForm Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.netbeans.modules.pdf;

import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author jhavlin
 */
public class SetCommandForm extends javax.swing.JPanel {

    private JFileChooser fileChooser;

    /**
     * Creates new form SetCommandForm
     */
    public SetCommandForm(String initialCommand) {
        initComponents();
        commandTextField.setText(initialCommand);
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // //GEN-BEGIN:initComponents
    private void initComponents() {

        commandLabel = new javax.swing.JLabel();
        fileToOpenLabel = new javax.swing.JLabel();
        commandTextField = new javax.swing.JTextField();
        browseButton = new javax.swing.JButton();

        commandLabel.setText(org.openide.util.NbBundle.getMessage(SetCommandForm.class, "SetCommandForm.commandLabel.text")); // NOI18N

        fileToOpenLabel.setText(org.openide.util.NbBundle.getMessage(SetCommandForm.class, "SetCommandForm.fileToOpenLabel.text")); // NOI18N

        commandTextField.setText(org.openide.util.NbBundle.getMessage(SetCommandForm.class, "SetCommandForm.commandTextField.text")); // NOI18N

        browseButton.setText(org.openide.util.NbBundle.getMessage(SetCommandForm.class, "SetCommandForm.browseButton.text")); // NOI18N
        browseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(commandTextField)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(commandLabel)
                            .addComponent(fileToOpenLabel))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(browseButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(commandLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(fileToOpenLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(commandTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(browseButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// //GEN-END:initComponents

    private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
        if (fileChooser == null) {
            fileChooser = new JFileChooser();
            fileChooser.setMultiSelectionEnabled(false);
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        }
        fileChooser.showOpenDialog(this);
        File f = fileChooser.getSelectedFile();
        if (f != null) {
            commandTextField.setText(f.getAbsolutePath()
                    + " " + PDFOpenSupport.FILENAME_PLACEHOLDER);       //NOI18N
        }
    }//GEN-LAST:event_browseButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton browseButton;
    private javax.swing.JLabel commandLabel;
    private javax.swing.JTextField commandTextField;
    private javax.swing.JLabel fileToOpenLabel;
    // End of variables declaration//GEN-END:variables

    public String getCommand() {
        return commandTextField.getText();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy