/* Copyright 2004-2014 Jim Voris * * 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.qumasoft.guitools.qwin.dialog; import com.qumasoft.guitools.qwin.QWinFrame; import com.qumasoft.guitools.qwin.operation.OperationSetCommentPrefix; import java.util.List; /** * Set comment prefix dialog. This dialog is the way a user * changes the comment prefix for an archive that already exists. * * @author Jim Voris */ public class SetCommentPrefixDialog extends AbstractQWinCommandDialog { private static final long serialVersionUID = -1185156818608627169L; private final QWinFrame parentFrame; private final List selectedFiles; private String commentPrefix; private final OperationSetCommentPrefix operationSetCommentPrefix; /** * Create a set comment prefix dialog. * @param parent the parent frame. * @param files the selected files. * @param operation the operation that will do the work. */ public SetCommentPrefixDialog(java.awt.Frame parent, List files, OperationSetCommentPrefix operation) { super(parent, true); this.selectedFiles = files; this.parentFrame = (QWinFrame) parent; this.operationSetCommentPrefix = operation; initComponents(); getRootPane().setDefaultButton(okButton); setFont(); center(); } /** 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() { okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); commentPrefixLabel = new javax.swing.JLabel(); commentPrefixTextArea = new javax.swing.JTextArea(); setTitle("Set Comment Prefix String"); setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N setResizable(false); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } }); okButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N okButton.setText(" OK "); okButton.setEnabled(false); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); cancelButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); commentPrefixLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N commentPrefixLabel.setLabelFor(commentPrefixTextArea); commentPrefixLabel.setText("Enter New Comment Prefix:"); commentPrefixTextArea.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N commentPrefixTextArea.setToolTipText("The comment prefix string is used when expanding the Log keyword."); commentPrefixTextArea.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); commentPrefixTextArea.setMaximumSize(new java.awt.Dimension(2, 17)); commentPrefixTextArea.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { commentPrefixTextAreaKeyReleased(evt); } }); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(layout.createSequentialGroup() .add(10, 10, 10) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(commentPrefixLabel) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(cancelButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(commentPrefixTextArea, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 270, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))) .add(18, 18, 18)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(20, 20, 20) .add(commentPrefixLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(commentPrefixTextArea, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(20, 20, 20) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(okButton) .add(cancelButton)) .add(13, 13, 13)) ); pack(); }// </editor-fold>//GEN-END:initComponents private void commentPrefixTextAreaKeyReleased(java.awt.event.KeyEvent evt)//GEN-FIRST:event_commentPrefixTextAreaKeyReleased {//GEN-HEADEREND:event_commentPrefixTextAreaKeyReleased // We only allow comment prefix strings that have some length. String currentCommentPrefix = commentPrefixTextArea.getText(); if (currentCommentPrefix.length() > 0) { okButton.setEnabled(true); } else { okButton.setEnabled(false); } }//GEN-LAST:event_commentPrefixTextAreaKeyReleased private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cancelButtonActionPerformed {//GEN-HEADEREND:event_cancelButtonActionPerformed closeDialog(null); }//GEN-LAST:event_cancelButtonActionPerformed private void okButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_okButtonActionPerformed {//GEN-HEADEREND:event_okButtonActionPerformed commentPrefix = commentPrefixTextArea.getText(); closeDialog(null); operationSetCommentPrefix.completeOperation(selectedFiles, getCommentPrefix()); }//GEN-LAST:event_okButtonActionPerformed /** Closes the dialog */ private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog setVisible(false); dispose(); }//GEN-LAST:event_closeDialog @Override public void dismissDialog() { cancelButtonActionPerformed(null); } private String getCommentPrefix() { return commentPrefix; } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; private javax.swing.JLabel commentPrefixLabel; private javax.swing.JTextArea commentPrefixTextArea; private javax.swing.JButton okButton; // End of variables declaration//GEN-END:variables }