content: /*
   * Copyright 2017 the original author or authors.
   *
   * Licensed 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 com.github.alexfalappa.nbspringboot.codegen;
  
  import java.awt.event.ActionEvent;
  import java.awt.event.KeyEvent;
  import java.util.HashSet;
  import java.util.Set;
  
  import javax.swing.AbstractAction;
  import javax.swing.ActionMap;
  import javax.swing.InputMap;
  import javax.swing.JComponent;
  import javax.swing.KeyStroke;
  
  import com.fasterxml.jackson.databind.JsonNode;
  
  /**
   * Dialog for selecting dependencies to add to a POM file.
   *
   * @author Alessandro Falappa
   */
  public class SpringDependencyDialog extends javax.swing.JDialog {
  
      /** A return status code - returned if Cancel button has been pressed */
      public static final int RET_CANCEL = 0;
      /** A return status code - returned if OK button has been pressed */
      public static final int RET_OK = 1;
  
      /**
       * Creates new dialog SpringDependencyDialog.
       *
       * @param parent the parent dialog.
       */
      public SpringDependencyDialog(java.awt.Frame parent) {
          super(parent, true);
          initComponents();
          // Close the dialog when Esc is pressed
          String cancelName = "cancel";
          InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
          inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
          ActionMap actionMap = rootPane.getActionMap();
          actionMap.put(cancelName, new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  doClose(RET_CANCEL);
              }
          });
      }
  
      public void init(JsonNode meta) {
          ippvDeps.init(meta);
          pack();
      }
  
      public void fixBootVersion(String bootVersion) {
          ippvDeps.fixBootVersion(bootVersion);
      }
  
      /**
       * Get the exit status.
       *
       * @return the return status of this dialog - one of RET_OK or RET_CANCEL
       */
      public int getReturnStatus() {
          return returnStatus;
      }
  
      public Set<String> getSelectedDeps() {
          return new HashSet<>(ippvDeps.getSelectedDeps());
      }
  
      /** 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")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
      private void initComponents() {
  
          okButton = new javax.swing.JButton();
          cancelButton = new javax.swing.JButton();
          ippvDeps = new com.github.alexfalappa.nbspringboot.projects.initializr.InitializrProjectPanelVisual2();
  
          setTitle(org.openide.util.NbBundle.getBundle(SpringDependencyDialog.class).getString("SpringDependencyDialog.title")); // NOI18N
          addWindowListener(new java.awt.event.WindowAdapter() {
              public void windowClosing(java.awt.event.WindowEvent evt) {
                  closeDialog(evt);
              }
          });
  
          org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getBundle(SpringDependencyDialog.class).getString("SpringDependencyDialog.okButton.text")); // NOI18N
          okButton.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  okButtonActionPerformed(evt);
              }
          });
  
          org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getBundle(SpringDependencyDialog.class).getString("SpringDependencyDialog.cancelButton.text")); // NOI18N
          cancelButton.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  cancelButtonActionPerformed(evt);
              }
          });
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(cancelButton)
                  .addContainerGap())
              .addComponent(ippvDeps, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          );
  
          layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
  
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                  .addComponent(ippvDeps, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addGap(18, 18, 18)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(cancelButton)
                      .addComponent(okButton))
                  .addContainerGap())
          );
  
          getRootPane().setDefaultButton(okButton);
  
          pack();
      }// </editor-fold>//GEN-END:initComponents
  
      private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
          doClose(RET_OK);
      }//GEN-LAST:event_okButtonActionPerformed
  
      private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
          doClose(RET_CANCEL);
      }//GEN-LAST:event_cancelButtonActionPerformed
  
      /** Closes the dialog */
      private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
          doClose(RET_CANCEL);
      }//GEN-LAST:event_closeDialog
  
      private void doClose(int retStatus) {
          returnStatus = retStatus;
          setVisible(false);
          dispose();
      }
  
      // Variables declaration - do not modify//GEN-BEGIN:variables
      private javax.swing.JButton cancelButton;
      private com.github.alexfalappa.nbspringboot.projects.initializr.InitializrProjectPanelVisual2 ippvDeps;
      private javax.swing.JButton okButton;
      // End of variables declaration//GEN-END:variables
      private int returnStatus = RET_CANCEL;
  
  }
  