82c70ead448627767f4267a3d7584d5a802c9f94
[habeas.git] / src / habeas / CreateNoticeDialog.java
1 /*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6 package habeas;
7
8 import java.text.DateFormat;
9 import java.text.SimpleDateFormat;
10 import java.util.ArrayList;
11 import java.util.Date;
12 import java.util.Random;
13 import javax.swing.JOptionPane;
14
15 /**
16 *
17 * @author hari
18 */
19 public class CreateNoticeDialog extends javax.swing.JDialog {
20
21 /**
22 * Creates new form CreateNoticeDialog
23 */
24 public CreateNoticeDialog(java.awt.Frame parent, boolean modal) {
25 super(parent, modal);
26 initComponents();
27 populateClients ();
28 }
29
30 /**
31 * This method is called from within the constructor to initialize the form.
32 * WARNING: Do NOT modify this code. The content of this method is always
33 * regenerated by the Form Editor.
34 */
35 @SuppressWarnings("unchecked")
36 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
37 private void initComponents() {
38
39 jScrollPane2 = new javax.swing.JScrollPane();
40 jList1 = new javax.swing.JList<>();
41 jLabel1 = new javax.swing.JLabel();
42 textReferenceNumber = new javax.swing.JTextField();
43 buttonAutogenerate = new javax.swing.JButton();
44 jLabel2 = new javax.swing.JLabel();
45 jScrollPane1 = new javax.swing.JScrollPane();
46 textDescription = new javax.swing.JTextArea();
47 dateEntrustment = new org.jdesktop.swingx.JXDatePicker();
48 jLabel3 = new javax.swing.JLabel();
49 jLabel4 = new javax.swing.JLabel();
50 clientsList = new javax.swing.JComboBox<>();
51 buttonAdd = new javax.swing.JButton();
52 buttonClose = new javax.swing.JButton();
53
54 jList1.setModel(new javax.swing.AbstractListModel<String>() {
55 String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
56 public int getSize() { return strings.length; }
57 public String getElementAt(int i) { return strings[i]; }
58 });
59 jScrollPane2.setViewportView(jList1);
60
61 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
62 setTitle("Create Lawyer Notice");
63 setLocationByPlatform(true);
64
65 jLabel1.setText("Reference Number");
66
67 buttonAutogenerate.setMnemonic('A');
68 buttonAutogenerate.setText("Autogen");
69 buttonAutogenerate.addActionListener(new java.awt.event.ActionListener() {
70 public void actionPerformed(java.awt.event.ActionEvent evt) {
71 buttonAutogenerateActionPerformed(evt);
72 }
73 });
74
75 jLabel2.setText("Description");
76
77 textDescription.setColumns(20);
78 textDescription.setRows(5);
79 jScrollPane1.setViewportView(textDescription);
80
81 jLabel3.setText("Entrustment Date");
82
83 jLabel4.setText("Client");
84
85 buttonAdd.setMnemonic('A');
86 buttonAdd.setText("Add");
87 buttonAdd.addActionListener(new java.awt.event.ActionListener() {
88 public void actionPerformed(java.awt.event.ActionEvent evt) {
89 buttonAddActionPerformed(evt);
90 }
91 });
92
93 buttonClose.setMnemonic('C');
94 buttonClose.setText("Close");
95 buttonClose.addActionListener(new java.awt.event.ActionListener() {
96 public void actionPerformed(java.awt.event.ActionEvent evt) {
97 buttonCloseActionPerformed(evt);
98 }
99 });
100
101 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
102 getContentPane().setLayout(layout);
103 layout.setHorizontalGroup(
104 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
105 .addGroup(layout.createSequentialGroup()
106 .addContainerGap()
107 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
108 .addGroup(layout.createSequentialGroup()
109 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
110 .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
111 .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
112 .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
113 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
114 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
115 .addGroup(layout.createSequentialGroup()
116 .addComponent(textReferenceNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
117 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
118 .addComponent(buttonAutogenerate, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE))
119 .addComponent(jScrollPane1)
120 .addComponent(dateEntrustment, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
121 .addGroup(layout.createSequentialGroup()
122 .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
123 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
124 .addComponent(clientsList, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
125 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
126 .addGap(0, 0, Short.MAX_VALUE)
127 .addComponent(buttonAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
128 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
129 .addComponent(buttonClose, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
130 .addContainerGap())
131 );
132 layout.setVerticalGroup(
133 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134 .addGroup(layout.createSequentialGroup()
135 .addContainerGap()
136 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
137 .addComponent(jLabel1)
138 .addComponent(textReferenceNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
139 .addComponent(buttonAutogenerate))
140 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
141 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
142 .addComponent(jLabel2)
143 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
144 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
145 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
146 .addComponent(dateEntrustment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
147 .addComponent(jLabel3))
148 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
149 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
150 .addComponent(clientsList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
151 .addComponent(jLabel4))
152 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
153 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
154 .addComponent(buttonAdd)
155 .addComponent(buttonClose))
156 .addContainerGap())
157 );
158
159 pack();
160 }// </editor-fold>//GEN-END:initComponents
161
162 private void buttonAutogenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAutogenerateActionPerformed
163 // TODO add your handling code here:
164 Random r = new Random (System.currentTimeMillis());
165 int randval = 1000 + r.nextInt(8999);
166 Date dt = new Date ();
167 dt.setTime(System.currentTimeMillis());
168 DateFormat dtfmt = new SimpleDateFormat("yyyyMMdd");
169
170 String strnotice = "NOTICE" + dtfmt.format (dt) + String.format("%d", randval);
171 textReferenceNumber.setText(strnotice);
172 }//GEN-LAST:event_buttonAutogenerateActionPerformed
173
174 private void buttonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseActionPerformed
175 // TODO add your handling code here:
176 dispose();
177 }//GEN-LAST:event_buttonCloseActionPerformed
178
179 private void buttonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddActionPerformed
180 // TODO add your handling code here:
181 boolean rt = Utility.addLegalNotice (textReferenceNumber.getText(),
182 textDescription.getText(), dateEntrustment.getDate(),
183 (DBItem)clientsList.getSelectedItem());
184 if (rt == true) {
185 JOptionPane.showMessageDialog(this , SUCCESSFULLY_ADDED);
186 clearFields ();
187 }
188 else {
189 JOptionPane.showMessageDialog(this, ERROR_IN_ADDING);
190 }
191 }//GEN-LAST:event_buttonAddActionPerformed
192 private static final String ERROR_IN_ADDING = "Error in adding";
193 private static final String SUCCESSFULLY_ADDED = "Successfully added";
194
195 /**
196 * @param args the command line arguments
197 */
198 public static void main(String args[]) {
199 /* Set the Nimbus look and feel */
200 //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
201 /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
202 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
203 */
204 try {
205 for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
206 if ("Nimbus".equals(info.getName())) {
207 javax.swing.UIManager.setLookAndFeel(info.getClassName());
208 break;
209 }
210 }
211 } catch (ClassNotFoundException ex) {
212 java.util.logging.Logger.getLogger(CreateNoticeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
213 } catch (InstantiationException ex) {
214 java.util.logging.Logger.getLogger(CreateNoticeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
215 } catch (IllegalAccessException ex) {
216 java.util.logging.Logger.getLogger(CreateNoticeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
217 } catch (javax.swing.UnsupportedLookAndFeelException ex) {
218 java.util.logging.Logger.getLogger(CreateNoticeDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
219 }
220 //</editor-fold>
221
222 /* Create and display the dialog */
223 java.awt.EventQueue.invokeLater(new Runnable() {
224 public void run() {
225 CreateNoticeDialog dialog = new CreateNoticeDialog(new javax.swing.JFrame(), true);
226 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
227 @Override
228 public void windowClosing(java.awt.event.WindowEvent e) {
229 System.exit(0);
230 }
231 });
232 dialog.setVisible(true);
233 }
234 });
235 }
236
237 // Variables declaration - do not modify//GEN-BEGIN:variables
238 private javax.swing.JButton buttonAdd;
239 private javax.swing.JButton buttonAutogenerate;
240 private javax.swing.JButton buttonClose;
241 private javax.swing.JComboBox<DBItem> clientsList;
242 private org.jdesktop.swingx.JXDatePicker dateEntrustment;
243 private javax.swing.JLabel jLabel1;
244 private javax.swing.JLabel jLabel2;
245 private javax.swing.JLabel jLabel3;
246 private javax.swing.JLabel jLabel4;
247 private javax.swing.JList<String> jList1;
248 private javax.swing.JScrollPane jScrollPane1;
249 private javax.swing.JScrollPane jScrollPane2;
250 private javax.swing.JTextArea textDescription;
251 private javax.swing.JTextField textReferenceNumber;
252 // End of variables declaration//GEN-END:variables
253
254 private void populateClients() {
255 ArrayList<Object> clients = Utility.getClientsNameAndId();
256 if (clients == null) return;
257 for (int i = 0; i < clients.size(); i += 2) {
258 clientsList.addItem(new DBItem
259 (Integer.parseInt(clients.get(i).toString()),
260 clients.get(i+1).toString()));
261 }
262 }
263
264 private void clearFields() {
265 textDescription.setText("");
266 textReferenceNumber.setText("");
267 dateEntrustment.setDate(null);
268 clientsList.setSelectedIndex(-1);
269 }
270 }