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