Package org.netbeans.modules.php.nette.options

Source Code of org.netbeans.modules.php.nette.options.NettePanel

/*
* The MIT license
*
* Copyright (c) 2010 Radek Ježdík <redhead@email.cz>, Ondřej Brejla <ondrej@brejla.cz>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package org.netbeans.modules.php.nette.options;

import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import org.netbeans.modules.php.nette.validators.NetteEmptyPathValidator;
import org.netbeans.modules.php.nette.validators.NetteLoaderExistsValidator;
import org.netbeans.modules.php.nette.validators.SandboxPathValidator;
import org.netbeans.modules.php.nette.validators.Validable;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;

final class NettePanel extends javax.swing.JPanel {

  private final NetteOptionsPanelController controller;

  private ImageIcon errorIcon = ImageUtilities.loadImageIcon("org/netbeans/modules/php/nette/resources/error_icon.png", true);

  NettePanel(NetteOptionsPanelController controller) {
    this.controller = controller;
    initComponents();
    // TODO listen to changes in form fields and call controller.changed()
    errorLabel.setText("");
  }

  /** 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.
   */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        netteFileChooser = new javax.swing.JFileChooser();
        sandboxDirectoryChooser = new javax.swing.JFileChooser();
        jLabel1 = new javax.swing.JLabel();
        netteFileTextField = new javax.swing.JTextField();
        netteBrowseButton = new javax.swing.JButton();
        errorLabel = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        sandboxLabel = new javax.swing.JLabel();
        sandboxPathTextField = new javax.swing.JTextField();
        sandboxBrowseButton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        sandboxDirectoryChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(NettePanel.class, "NettePanel.jLabel1.text")); // NOI18N

        netteFileTextField.setText(org.openide.util.NbBundle.getMessage(NettePanel.class, "NettePanel.netteFileTextField.text")); // NOI18N
        netteFileTextField.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                netteFileTextFieldCaretUpdate(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(netteBrowseButton, org.openide.util.NbBundle.getMessage(NettePanel.class, "NettePanel.netteBrowseButton.text")); // NOI18N
        netteBrowseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                netteBrowseButtonActionPerformed(evt);
            }
        });

        errorLabel.setForeground(javax.swing.UIManager.getDefaults().getColor("nb.errorForeground"));
        errorLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(NettePanel.class, "NettePanel.errorLabel.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(NettePanel.class, "NettePanel.jLabel2.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(sandboxLabel, org.openide.util.NbBundle.getMessage(NettePanel.class, "NettePanel.sandboxLabel.text")); // NOI18N

        sandboxPathTextField.setText(org.openide.util.NbBundle.getMessage(NettePanel.class, "NettePanel.sandboxPathTextField.text")); // NOI18N
        sandboxPathTextField.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                sandboxPathTextFieldCaretUpdate(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(sandboxBrowseButton, org.openide.util.NbBundle.getMessage(NettePanel.class, "NettePanel.sandboxBrowseButton.text")); // NOI18N
        sandboxBrowseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sandboxBrowseButtonActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(NettePanel.class, "NettePanel.jLabel3.text")); // NOI18N

        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)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(netteFileTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(netteBrowseButton))
                    .addComponent(errorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(sandboxLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sandboxPathTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sandboxBrowseButton))
                    .addComponent(jLabel3)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(netteFileTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(netteBrowseButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sandboxLabel)
                    .addComponent(sandboxPathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sandboxBrowseButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(errorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

  private void netteBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_netteBrowseButtonActionPerformed
    int result = netteFileChooser.showOpenDialog(this);

        if (result == JFileChooser.APPROVE_OPTION) {
            netteFileTextField.setText(netteFileChooser.getSelectedFile().toString());
            controller.changed();
        }
  }//GEN-LAST:event_netteBrowseButtonActionPerformed

  private void netteFileTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_netteFileTextFieldCaretUpdate
    controller.changed();
  }//GEN-LAST:event_netteFileTextFieldCaretUpdate

  private void sandboxPathTextFieldCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_sandboxPathTextFieldCaretUpdate
    controller.changed();
  }//GEN-LAST:event_sandboxPathTextFieldCaretUpdate

  private void sandboxBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sandboxBrowseButtonActionPerformed
    int result = sandboxDirectoryChooser.showOpenDialog(this);

        if (result == JFileChooser.APPROVE_OPTION) {
            sandboxPathTextField.setText(sandboxDirectoryChooser.getSelectedFile().toString());
            controller.changed();
        }
  }//GEN-LAST:event_sandboxBrowseButtonActionPerformed

  void load() {
    netteFileTextField.setText(NetteOptions.getInstance().getNetteFile());
    sandboxPathTextField.setText(NetteOptions.getInstance().getSandboxPath());
  }

  void store() {
    NetteOptions.getInstance().setNetteFile(netteFileTextField.getText());
    NetteOptions.getInstance().setSandboxPath(sandboxPathTextField.getText());
  }

  boolean valid() {
    Validable sandboxPathValidator = new SandboxPathValidator();

    if (!isNetteFileValid()) {
      errorLabel.setIcon(errorIcon);
      errorLabel.setText(NbBundle.getMessage(NettePanel.class, "ERR_invalid_nette_file"));

      return false;
    } else if (!sandboxPathValidator.validate(sandboxPathTextField.getText())) {
      errorLabel.setIcon(errorIcon);
      errorLabel.setText(NbBundle.getMessage(NettePanel.class, "ERR_invalid_sandbox_folder"));

      return false;
    } else {
      errorLabel.setIcon(null);
      errorLabel.setText("");

      return true;
    }
  }

  private boolean isNetteFileValid() {
    Validable loaderExistsValidator = new NetteLoaderExistsValidator();
    Validable emptyPathValidator = new NetteEmptyPathValidator();

    return loaderExistsValidator.validate(netteFileTextField.getText()) || emptyPathValidator.validate(netteFileTextField.getText());
  }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel errorLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton netteBrowseButton;
    private javax.swing.JFileChooser netteFileChooser;
    private javax.swing.JTextField netteFileTextField;
    private javax.swing.JButton sandboxBrowseButton;
    private javax.swing.JFileChooser sandboxDirectoryChooser;
    private javax.swing.JLabel sandboxLabel;
    private javax.swing.JTextField sandboxPathTextField;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of org.netbeans.modules.php.nette.options.NettePanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.