/* 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.OperationSetModuleDescription;
import com.qumasoft.qvcslib.MergedInfoInterface;
import java.util.List;
/**
* Set module description dialog. This dialog is the way a user
* changes the module description for an archive that already exists.
*
* @author Jim Voris
*/
public class SetModuleDescriptionDialog extends AbstractQWinCommandDialog {
private static final long serialVersionUID = 7192634037510303477L;
private final QWinFrame parentFrame;
private final List selectedFiles;
private String moduleDescription;
private final OperationSetModuleDescription operationSetModuleDescription;
/**
* Set module description dialog.
* @param parent parent frame.
* @param files the selected files.
* @param operation the operation that will do the work.
*/
public SetModuleDescriptionDialog(java.awt.Frame parent, List files, OperationSetModuleDescription operation) {
super(parent, true);
selectedFiles = files;
parentFrame = (QWinFrame) parent;
operationSetModuleDescription = operation;
initComponents();
populateExistingFileDescription();
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() {
currentModuleDescriptionLabel = new javax.swing.JLabel();
moduleDescriptionLabel = new javax.swing.JLabel();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
existingDescriptionOfFileTextArea = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
descriptionOfFileTextArea = new javax.swing.JTextArea();
setTitle("Set File Description");
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);
}
});
currentModuleDescriptionLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
currentModuleDescriptionLabel.setLabelFor(descriptionOfFileTextArea);
currentModuleDescriptionLabel.setText("Existing Description:");
moduleDescriptionLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
moduleDescriptionLabel.setLabelFor(descriptionOfFileTextArea);
moduleDescriptionLabel.setText("Enter New Description:");
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);
}
});
existingDescriptionOfFileTextArea.setEditable(false);
existingDescriptionOfFileTextArea.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
existingDescriptionOfFileTextArea.setLineWrap(true);
existingDescriptionOfFileTextArea.setRows(10);
existingDescriptionOfFileTextArea.setTabSize(4);
existingDescriptionOfFileTextArea.setWrapStyleWord(true);
existingDescriptionOfFileTextArea.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
existingDescriptionOfFileTextArea.setMaximumSize(new java.awt.Dimension(102, 120));
existingDescriptionOfFileTextArea.setMinimumSize(new java.awt.Dimension(102, 120));
jScrollPane1.setViewportView(existingDescriptionOfFileTextArea);
descriptionOfFileTextArea.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
descriptionOfFileTextArea.setLineWrap(true);
descriptionOfFileTextArea.setRows(10);
descriptionOfFileTextArea.setTabSize(4);
descriptionOfFileTextArea.setToolTipText("Enter new file description.");
descriptionOfFileTextArea.setWrapStyleWord(true);
descriptionOfFileTextArea.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
descriptionOfFileTextArea.setDoubleBuffered(true);
descriptionOfFileTextArea.setMaximumSize(new java.awt.Dimension(102, 120));
descriptionOfFileTextArea.setMinimumSize(new java.awt.Dimension(102, 120));
descriptionOfFileTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
descriptionOfFileTextAreaKeyReleased(evt);
}
});
jScrollPane2.setViewportView(descriptionOfFileTextArea);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.addContainerGap()
.add(moduleDescriptionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.addContainerGap()
.add(currentModuleDescriptionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 384, Short.MAX_VALUE))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(10, 10, 10)
.add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 180, Short.MAX_VALUE)
.add(cancelButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(16, 16, 16))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(12, 12, 12)
.add(currentModuleDescriptionLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(24, 24, 24)
.add(moduleDescriptionLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(okButton)
.add(cancelButton))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void descriptionOfFileTextAreaKeyReleased(java.awt.event.KeyEvent evt)//GEN-FIRST:event_descriptionOfFileTextAreaKeyReleased
{//GEN-HEADEREND:event_descriptionOfFileTextAreaKeyReleased
// We only allow module description strings that have some length.
String currentModuleDescription = descriptionOfFileTextArea.getText();
if (currentModuleDescription.length() > 0) {
okButton.setEnabled(true);
} else {
okButton.setEnabled(false);
}
}//GEN-LAST:event_descriptionOfFileTextAreaKeyReleased
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
moduleDescription = descriptionOfFileTextArea.getText();
closeDialog(null);
operationSetModuleDescription.completeOperation(selectedFiles, getModuleDescription());
}//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 getModuleDescription() {
return moduleDescription;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JLabel currentModuleDescriptionLabel;
private javax.swing.JTextArea descriptionOfFileTextArea;
private javax.swing.JTextArea existingDescriptionOfFileTextArea;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JLabel moduleDescriptionLabel;
private javax.swing.JButton okButton;
// End of variables declaration//GEN-END:variables
/**
* Fill in the text area controls with the existing file description...
*/
private void populateExistingFileDescription() {
MergedInfoInterface mergedInfo = (MergedInfoInterface) selectedFiles.get(0);
String fileDescription = mergedInfo.getArchiveInfo().getLogfileInfo().getLogFileHeaderInfo().getModuleDescription();
existingDescriptionOfFileTextArea.setText(fileDescription);
descriptionOfFileTextArea.setText(fileDescription);
descriptionOfFileTextArea.select(0, fileDescription.length());
descriptionOfFileTextArea.requestFocusInWindow();
}
}