From 9a41ac52640b4316b9b69817cb4bc1298d0bd749 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Mon, 30 Mar 2020 14:31:18 +0530 Subject: [PATCH] Add Legal Notice functionality Created the screen for adding a new legal notice. --- src/habeas/ClientMasterDialog.form | 1 + src/habeas/ClientMasterDialog.java | 5 +- src/habeas/CreateNoticeDialog.form | 203 +++++++++++++++++++ src/habeas/CreateNoticeDialog.java | 270 +++++++++++++++++++++++++ src/habeas/DBItem.java | 31 +++ src/habeas/DatabaseSettingsDialog.java | 1 - src/habeas/Habeas.java | 1 - src/habeas/MainFrame.form | 17 ++ src/habeas/MainFrame.java | 24 +++ src/habeas/Utility.java | 28 ++- 10 files changed, 572 insertions(+), 9 deletions(-) create mode 100644 src/habeas/CreateNoticeDialog.form create mode 100644 src/habeas/CreateNoticeDialog.java create mode 100644 src/habeas/DBItem.java diff --git a/src/habeas/ClientMasterDialog.form b/src/habeas/ClientMasterDialog.form index e7d0b7c..31b9acc 100644 --- a/src/habeas/ClientMasterDialog.form +++ b/src/habeas/ClientMasterDialog.form @@ -4,6 +4,7 @@ + diff --git a/src/habeas/ClientMasterDialog.java b/src/habeas/ClientMasterDialog.java index a17d2a1..29ff74e 100644 --- a/src/habeas/ClientMasterDialog.java +++ b/src/habeas/ClientMasterDialog.java @@ -9,11 +9,7 @@ import java.util.ArrayList; import javax.swing.JOptionPane; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.plaf.basic.BasicListUI; import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableModel; /** * @@ -107,6 +103,7 @@ public class ClientMasterDialog extends javax.swing.JDialog { setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Clients Master"); + setLocationByPlatform(true); tableClients.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { diff --git a/src/habeas/CreateNoticeDialog.form b/src/habeas/CreateNoticeDialog.form new file mode 100644 index 0000000..2c75434 --- /dev/null +++ b/src/habeas/CreateNoticeDialog.form @@ -0,0 +1,203 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/habeas/CreateNoticeDialog.java b/src/habeas/CreateNoticeDialog.java new file mode 100644 index 0000000..82c70ea --- /dev/null +++ b/src/habeas/CreateNoticeDialog.java @@ -0,0 +1,270 @@ +/* + * 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") + // //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[] 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(); + }// //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 */ + // + /* 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); + } + // + + /* 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 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 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 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); + } +} diff --git a/src/habeas/DBItem.java b/src/habeas/DBItem.java new file mode 100644 index 0000000..9083ca5 --- /dev/null +++ b/src/habeas/DBItem.java @@ -0,0 +1,31 @@ +/* + * 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; + +/** + * + * @author hari + */ +public class DBItem { + private final int key; + private final String value; + public DBItem (int k, String v) { + key = k; + value = v; + } + + /** + * + * @return + */ + @Override + public String toString () { + return value; + } + public int getKey () { + return key; + } +} diff --git a/src/habeas/DatabaseSettingsDialog.java b/src/habeas/DatabaseSettingsDialog.java index 5a9ce9b..0b7475f 100644 --- a/src/habeas/DatabaseSettingsDialog.java +++ b/src/habeas/DatabaseSettingsDialog.java @@ -5,7 +5,6 @@ */ package habeas; -import java.util.prefs.Preferences; import javax.swing.JFileChooser; /** diff --git a/src/habeas/Habeas.java b/src/habeas/Habeas.java index 5932034..e6fa843 100644 --- a/src/habeas/Habeas.java +++ b/src/habeas/Habeas.java @@ -5,7 +5,6 @@ */ package habeas; -import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.UIManager; diff --git a/src/habeas/MainFrame.form b/src/habeas/MainFrame.form index ee56f86..cd41daa 100644 --- a/src/habeas/MainFrame.form +++ b/src/habeas/MainFrame.form @@ -20,6 +20,23 @@ + + + + + + + + + + + + + + + + + diff --git a/src/habeas/MainFrame.java b/src/habeas/MainFrame.java index 28477ad..c40672c 100644 --- a/src/habeas/MainFrame.java +++ b/src/habeas/MainFrame.java @@ -30,6 +30,8 @@ public class MainFrame extends javax.swing.JFrame { jMenuBar1 = new javax.swing.JMenuBar(); menuMaster = new javax.swing.JMenu(); menuClientMaster = new javax.swing.JMenuItem(); + menuLawyerNotices = new javax.swing.JMenu(); + menuCreateNotice = new javax.swing.JMenuItem(); menuSettings = new javax.swing.JMenu(); menuDatabaseSettings = new javax.swing.JMenuItem(); @@ -50,6 +52,20 @@ public class MainFrame extends javax.swing.JFrame { jMenuBar1.add(menuMaster); + menuLawyerNotices.setMnemonic('L'); + menuLawyerNotices.setText("Lawyer Notices"); + + menuCreateNotice.setMnemonic('C'); + menuCreateNotice.setText("Create New..."); + menuCreateNotice.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + menuCreateNoticeActionPerformed(evt); + } + }); + menuLawyerNotices.add(menuCreateNotice); + + jMenuBar1.add(menuLawyerNotices); + menuSettings.setMnemonic('S'); menuSettings.setText("Settings"); @@ -92,6 +108,12 @@ public class MainFrame extends javax.swing.JFrame { frm.setVisible(true); }//GEN-LAST:event_menuClientMasterActionPerformed + private void menuCreateNoticeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuCreateNoticeActionPerformed + // TODO add your handling code here: + CreateNoticeDialog frm = new CreateNoticeDialog(this, true); + frm.setVisible(true); + }//GEN-LAST:event_menuCreateNoticeActionPerformed + /** * @param args the command line arguments */ @@ -130,7 +152,9 @@ public class MainFrame extends javax.swing.JFrame { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem menuClientMaster; + private javax.swing.JMenuItem menuCreateNotice; private javax.swing.JMenuItem menuDatabaseSettings; + private javax.swing.JMenu menuLawyerNotices; private javax.swing.JMenu menuMaster; private javax.swing.JMenu menuSettings; // End of variables declaration//GEN-END:variables diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index 3eabd87..8b27e7e 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -8,11 +8,8 @@ package habeas; import java.util.ArrayList; import java.util.prefs.Preferences; import java.sql.*; -import java.util.Dictionary; -import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.JOptionPane; /** * @@ -116,6 +113,31 @@ public class Utility { } + } + + static boolean addLegalNotice(String reference_number, + String description, java.util.Date entrustment_date, DBItem client) { + if ("".equals(reference_number) || "".equals(description) || + entrustment_date == null) + return false; + try { + Connection conn = DriverManager.getConnection("jdbc:sqlite:" + connectionURL); + PreparedStatement st = conn.prepareStatement("INSERT INTO legalnotices" + + " (ReferenceNumber, Description, EntrustmentDate, ClientId) " + + "VALUES (?, ?, ?, ?);"); + st.setString(1, reference_number); + st.setString(2, description); + st.setLong(3, entrustment_date.getTime()/1000); + st.setInt (4, client.getKey()); + st.execute(); + conn.close(); + return true; + + } catch (SQLException ex) { + Logger.getLogger(Utility.class.getName()).log(Level.SEVERE, null, ex); + return false; + } + } public Utility () { -- 2.20.1