+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package habeas;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Random;
+import javax.swing.JOptionPane;
+
+/**
+ *
+ * @author hari
+ */
+public class CreateNoticeDialog extends javax.swing.JDialog {
+
+ /**
+ * Creates new form CreateNoticeDialog
+ */
+ public CreateNoticeDialog(java.awt.Frame parent, boolean modal) {
+ super(parent, modal);
+ initComponents();
+ populateClients ();
+ }
+
+ /**
+ * 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() {
+
+ jScrollPane2 = new javax.swing.JScrollPane();
+ jList1 = new javax.swing.JList<>();
+ jLabel1 = new javax.swing.JLabel();
+ textReferenceNumber = new javax.swing.JTextField();
+ buttonAutogenerate = new javax.swing.JButton();
+ jLabel2 = new javax.swing.JLabel();
+ jScrollPane1 = new javax.swing.JScrollPane();
+ textDescription = new javax.swing.JTextArea();
+ dateEntrustment = new org.jdesktop.swingx.JXDatePicker();
+ jLabel3 = new javax.swing.JLabel();
+ jLabel4 = new javax.swing.JLabel();
+ clientsList = new javax.swing.JComboBox<>();
+ buttonAdd = new javax.swing.JButton();
+ buttonClose = new javax.swing.JButton();
+
+ jList1.setModel(new javax.swing.AbstractListModel<String>() {
+ String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
+ public int getSize() { return strings.length; }
+ public String getElementAt(int i) { return strings[i]; }
+ });
+ jScrollPane2.setViewportView(jList1);
+
+ setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
+ setTitle("Create Lawyer Notice");
+ setLocationByPlatform(true);
+
+ jLabel1.setText("Reference Number");
+
+ buttonAutogenerate.setMnemonic('A');
+ buttonAutogenerate.setText("Autogen");
+ buttonAutogenerate.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonAutogenerateActionPerformed(evt);
+ }
+ });
+
+ jLabel2.setText("Description");
+
+ textDescription.setColumns(20);
+ textDescription.setRows(5);
+ jScrollPane1.setViewportView(textDescription);
+
+ jLabel3.setText("Entrustment Date");
+
+ jLabel4.setText("Client");
+
+ buttonAdd.setMnemonic('A');
+ buttonAdd.setText("Add");
+ buttonAdd.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonAddActionPerformed(evt);
+ }
+ });
+
+ buttonClose.setMnemonic('C');
+ buttonClose.setText("Close");
+ buttonClose.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonCloseActionPerformed(evt);
+ }
+ });
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+ getContentPane().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()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
+ .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
+ .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(textReferenceNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonAutogenerate, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE))
+ .addComponent(jScrollPane1)
+ .addComponent(dateEntrustment, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(clientsList, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addGap(0, 0, Short.MAX_VALUE)
+ .addComponent(buttonAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(buttonClose, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
+ .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(textReferenceNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(buttonAutogenerate))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel2)
+ .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(dateEntrustment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel3))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(clientsList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel4))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(buttonAdd)
+ .addComponent(buttonClose))
+ .addContainerGap())
+ );
+
+ pack();
+ }// </editor-fold>//GEN-END:initComponents
+
+ private void buttonAutogenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAutogenerateActionPerformed
+ // TODO add your handling code here:
+ Random r = new Random (System.currentTimeMillis());
+ int randval = 1000 + r.nextInt(8999);
+ Date dt = new Date ();
+ dt.setTime(System.currentTimeMillis());
+ DateFormat dtfmt = new SimpleDateFormat("yyyyMMdd");
+
+ String strnotice = "NOTICE" + dtfmt.format (dt) + String.format("%d", randval);
+ textReferenceNumber.setText(strnotice);
+ }//GEN-LAST:event_buttonAutogenerateActionPerformed
+
+ private void buttonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseActionPerformed
+ // TODO add your handling code here:
+ dispose();
+ }//GEN-LAST:event_buttonCloseActionPerformed
+
+ private void buttonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddActionPerformed
+ // TODO add your handling code here:
+ boolean rt = Utility.addLegalNotice (textReferenceNumber.getText(),
+ textDescription.getText(), dateEntrustment.getDate(),
+ (DBItem)clientsList.getSelectedItem());
+ if (rt == true) {
+ JOptionPane.showMessageDialog(this , SUCCESSFULLY_ADDED);
+ clearFields ();
+ }
+ else {
+ JOptionPane.showMessageDialog(this, ERROR_IN_ADDING);
+ }
+ }//GEN-LAST:event_buttonAddActionPerformed
+ private static final String ERROR_IN_ADDING = "Error in adding";
+ private static final String SUCCESSFULLY_ADDED = "Successfully added";
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ /* Set the Nimbus look and feel */
+ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
+ /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
+ * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
+ */
+ try {
+ for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(info.getName())) {
+ javax.swing.UIManager.setLookAndFeel(info.getClassName());
+ break;
+ }
+ }
+ } catch (ClassNotFoundException ex) {
+ java.util.logging.Logger.getLogger(CreateNoticeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (InstantiationException ex) {
+ java.util.logging.Logger.getLogger(CreateNoticeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (IllegalAccessException ex) {
+ java.util.logging.Logger.getLogger(CreateNoticeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ } catch (javax.swing.UnsupportedLookAndFeelException ex) {
+ java.util.logging.Logger.getLogger(CreateNoticeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+ }
+ //</editor-fold>
+
+ /* Create and display the dialog */
+ java.awt.EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ CreateNoticeDialog dialog = new CreateNoticeDialog(new javax.swing.JFrame(), true);
+ dialog.addWindowListener(new java.awt.event.WindowAdapter() {
+ @Override
+ public void windowClosing(java.awt.event.WindowEvent e) {
+ System.exit(0);
+ }
+ });
+ dialog.setVisible(true);
+ }
+ });
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton buttonAdd;
+ private javax.swing.JButton buttonAutogenerate;
+ private javax.swing.JButton buttonClose;
+ private javax.swing.JComboBox<DBItem> clientsList;
+ private org.jdesktop.swingx.JXDatePicker dateEntrustment;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JList<String> jList1;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JScrollPane jScrollPane2;
+ private javax.swing.JTextArea textDescription;
+ private javax.swing.JTextField textReferenceNumber;
+ // End of variables declaration//GEN-END:variables
+
+ private void populateClients() {
+ ArrayList<Object> clients = Utility.getClientsNameAndId();
+ if (clients == null) return;
+ for (int i = 0; i < clients.size(); i += 2) {
+ clientsList.addItem(new DBItem
+ (Integer.parseInt(clients.get(i).toString()),
+ clients.get(i+1).toString()));
+ }
+ }
+
+ private void clearFields() {
+ textDescription.setText("");
+ textReferenceNumber.setText("");
+ dateEntrustment.setDate(null);
+ clientsList.setSelectedIndex(-1);
+ }
+}