1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.bestray.healthcarecommonutil.views;
import com.bestray.healthcarecommonutil.ContextLoading;
import com.bestray.healthcarecommonutil.controller.MedicineController;
import com.bestray.healthcarecommonutil.exception.ProcessingException;
import com.bestray.healthcarecommonutil.util.DisabledGlassPane;
import com.bestray.healthcarecommonutil.util.Initcap;
import com.bestray.healthcarecommonutil.util.TextPrompt;
import com.bestray.healthcarecommonutil.vo.TMedicationMaster;
import java.awt.Color;
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.JRootPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
/**
*
* @author user3
*/
public class MedicationDialog extends javax.swing.JDialog {
/**
* Creates new form MedicationDialog
*/
public MedicationDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
populate();
initComponents();
TextPrompt tp7 = new TextPrompt("Search For Medication", searchmedtb);
tp7.setForeground( Color.RED );
tp7.changeAlpha(0.5f);
tp7.changeStyle(Font.BOLD);
showDataInTable(medlist);
}
/**
* 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() {
searchTreatment_panel = new javax.swing.JPanel();
tabpanel = new javax.swing.JTabbedPane();
jPanel3 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
medicationSearchTable = new javax.swing.JTable(){
public boolean isCellEditable(int row, int column){
return false;
}
public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) {
Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
if (rowIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) {
c.setForeground(Color.BLACK);
c.setBackground(new Color(200, 225, 250));
}
else if(rowIndex % 2 == 0 && isCellSelected(rowIndex, vColIndex)){
c.setForeground(Color.WHITE);
c.setBackground(Color.BLUE);
}
else if(rowIndex % 2 != 0 && isCellSelected(rowIndex, vColIndex)){
c.setForeground(Color.WHITE);
c.setBackground(Color.BLUE);
}
else {
c.setForeground(Color.BLACK);
c.setBackground(getBackground());
}
return c;
}
};
jToolBar1 = new javax.swing.JToolBar();
searchmedtb = new javax.swing.JTextField();
searchbutton = new javax.swing.JButton();
add_btn = new javax.swing.JButton();
jToolBar2 = new javax.swing.JToolBar();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Medication Search");
searchTreatment_panel.setOpaque(false);
tabpanel.setFont(new java.awt.Font("SansSerif", 1, 12)); // NOI18N
jPanel3.setOpaque(false);
jPanel3.setLayout(new java.awt.BorderLayout());
jScrollPane1.setBorder(null);
medicationSearchTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null},
{null, null}
},
new String [] {
"Title 1", "Title 2"
}
));
medicationSearchTable.setRowHeight(25);
medicationSearchTable.getTableHeader().setReorderingAllowed(false);
medicationSearchTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
medicationSearchTableMouseClicked(evt);
}
});
jScrollPane1.setViewportView(medicationSearchTable);
jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
tabpanel.addTab("Medication Information", jPanel3);
jToolBar1.setFloatable(false);
jToolBar1.setRollover(true);
jToolBar1.setOpaque(false);
searchmedtb.setMaximumSize(new java.awt.Dimension(200, 30));
searchmedtb.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
searchmedtbKeyPressed(evt);
}
});
jToolBar1.add(searchmedtb);
searchbutton.setFont(new java.awt.Font("SansSerif", 1, 10)); // NOI18N
searchbutton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/search-icon16X16.png"))); // NOI18N
searchbutton.setText("Search");
searchbutton.setOpaque(false);
searchbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
searchbuttonActionPerformed(evt);
}
});
jToolBar1.add(searchbutton);
add_btn.setFont(new java.awt.Font("SansSerif", 1, 10)); // NOI18N
add_btn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Done 16X16.png"))); // NOI18N
add_btn.setText("Done");
add_btn.setMargin(new java.awt.Insets(2, 16, 2, 16));
add_btn.setOpaque(false);
add_btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
add_btnActionPerformed(evt);
}
});
jToolBar1.add(add_btn);
jToolBar2.setFloatable(false);
jToolBar2.setRollover(true);
jToolBar2.setOpaque(false);
jButton1.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Add-icon16x16.png"))); // NOI18N
jButton1.setText("New Medicine");
jButton1.setFocusable(false);
jButton1.setMargin(new java.awt.Insets(2, 16, 2, 16));
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jToolBar2.add(jButton1);
javax.swing.GroupLayout searchTreatment_panelLayout = new javax.swing.GroupLayout(searchTreatment_panel);
searchTreatment_panel.setLayout(searchTreatment_panelLayout);
searchTreatment_panelLayout.setHorizontalGroup(
searchTreatment_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(searchTreatment_panelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(searchTreatment_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tabpanel, javax.swing.GroupLayout.DEFAULT_SIZE, 698, Short.MAX_VALUE)
.addGroup(searchTreatment_panelLayout.createSequentialGroup()
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
searchTreatment_panelLayout.setVerticalGroup(
searchTreatment_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(searchTreatment_panelLayout.createSequentialGroup()
.addGroup(searchTreatment_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tabpanel, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
.addContainerGap())
);
getContentPane().add(searchTreatment_panel, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
private void searchmedtbKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchmedtbKeyPressed
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
searchbutton.doClick();
}
}//GEN-LAST:event_searchmedtbKeyPressed
private void searchbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchbuttonActionPerformed
rootPane = SwingUtilities.getRootPane(this);
glassPane = new DisabledGlassPane();
if(searchmedtb.getText().length()>=0){
medlist = new Vector<TMedicationMaster>();
try {
expr = Initcap.toInitCap(searchmedtb.getText());
SwingWorker s = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
rootPane.setGlassPane(glassPane);
glassPane.activateLoadingImage();
medlist= medicineController.getMedicationByName(expr);
return medlist;
}
@Override
protected void done() {
if(medlist.size()!=0){
super.done();
glassPane.deactivate();
showDataInTable(medlist);
}else{
JOptionPane.showMessageDialog(null, "No medication present");
glassPane.deactivate();
searchmedtb.setText(null);
}
}
};
s.execute();
}catch (Exception ex) {
Logger.getLogger(MyFavMedicationSearchDialog.class.getName()).log(Level.SEVERE, null, ex);
}
}else{
JOptionPane.showMessageDialog(null, "Search filed is empty");
}
}//GEN-LAST:event_searchbuttonActionPerformed
private void medicationSearchTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_medicationSearchTableMouseClicked
event = evt;
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
if(event.getClickCount()==1){
if(medicationSearchTable!=null){
int row = medicationSearchTable.getSelectedRow();
if(medicationSearchTable.getValueAt(row, 0).equals(false)){
medicationSearchTable.setValueAt(true, row, 0);
}else{
medicationSearchTable.setValueAt(false, row, 0);
}
}
}
}
});
}//GEN-LAST:event_medicationSearchTableMouseClicked
private void add_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_add_btnActionPerformed
selectedMedicationList = new ArrayList<TMedicationMaster>();
for(int row=0;row<medicationSearchTable.getRowCount();row++){
if(medicationSearchTable.getValueAt(row, 0).equals(true)){
TMedicationMaster treatments = (TMedicationMaster)medicationSearchTable.getValueAt(row, 4);
selectedMedicationList.add(treatments);
}
}
if(selectedMedicationList.size()==0){
JOptionPane.showMessageDialog(null, "No Medication selected");
}else{
Set settreatment = new HashSet(selectedMedicationList);
selectedMedicationList.clear();
selectedMedicationList.addAll(settreatment);
this.dispose();
}
}//GEN-LAST:event_add_btnActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
DisabledGlassPane glassPane = new DisabledGlassPane();
JRootPane rootPane = SwingUtilities.getRootPane(this);
rootPane.setGlassPane(glassPane);
QuickMedicationEntryDialog resultDialoge = new QuickMedicationEntryDialog(MainAPP, true);
resultDialoge.setResizable(false);
resultDialoge.setLocationRelativeTo(null);
glassPane.activate("");
resultDialoge.setVisible(true);
resultDialoge.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
glassPane.deactivate();
searchbutton.doClick();
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @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(MedicationDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MedicationDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MedicationDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MedicationDialog.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() {
MedicationDialog dialog = new MedicationDialog(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 add_btn;
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JToolBar jToolBar1;
private javax.swing.JToolBar jToolBar2;
private javax.swing.JTable medicationSearchTable;
private javax.swing.JPanel searchTreatment_panel;
private javax.swing.JButton searchbutton;
private javax.swing.JTextField searchmedtb;
private javax.swing.JTabbedPane tabpanel;
// End of variables declaration//GEN-END:variables
private java.awt.event.MouseEvent event;
private DisabledGlassPane glassPane;
private String expr;
private DefaultTableModel model;
private Vector<Object> addObject;
private Vector<TMedicationMaster> medlist = new Vector<TMedicationMaster>();
private List<TMedicationMaster> selectedMedicationList = new ArrayList<TMedicationMaster>();
private MedicineController medicineController;
private javax.swing.JFrame MainAPP;
private void populate() {
medicineController=(MedicineController)ContextLoading.context.getBean("medicineController");
try {
medlist = medicineController.getAllMedication();
} catch (ProcessingException ex) {
Logger.getLogger(MedicationDialog.class.getName()).log(Level.SEVERE, null, ex);
}
}
public List<TMedicationMaster> getselectedMed(){
return selectedMedicationList;
}
private void showDataInTable(Vector<TMedicationMaster> medlist) {
medicationSearchTable.setModel(new javax.swing.table.DefaultTableModel(new Object [][] {},
new String [] {"Select","Medication Name","Dose","Frequency","MedObj"}){
Class[] types = new Class [] {java.lang.Boolean.class,java.lang.String.class,java.lang.String.class,java.lang.String.class,java.lang.Object.class};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
medicationSearchTable.getColumn("Select").setCellEditor(new DefaultCellEditor(new JCheckBox()));
medicationSearchTable.getTableHeader().setFont(new Font("SansSerif", Font.BOLD, 11));
medicationSearchTable.getColumnModel().getColumn(0).setMinWidth(50);
medicationSearchTable.getColumnModel().getColumn(0).setPreferredWidth(50);
medicationSearchTable.getColumnModel().getColumn(0).setMaxWidth(50);
medicationSearchTable.getColumnModel().getColumn(4).setMinWidth(0);
medicationSearchTable.getColumnModel().getColumn(4).setPreferredWidth(0);
medicationSearchTable.getColumnModel().getColumn(4).setMaxWidth(0);
medicationSearchTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
model = (DefaultTableModel)medicationSearchTable.getModel();
for(TMedicationMaster m:medlist){
addObject = new Vector<Object>();
addObject.add(new Boolean(false));
addObject.add(m.getMedicationName());
addObject.add(m.getMedicationDose());
addObject.add(m.getMedicationFrequency());
addObject.add(m);
model.addRow(addObject);
}
}
}
|