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
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.bestray.healthcareemr.Views;
import com.bestray.healthcarecommonutil.util.SimpleGradientPanel;
import com.bestray.healthcarecommonutil.vo.TAppointment;
import com.bestray.healthcarecommonutil.vo.TPatientEncounter;
import com.bestray.healthcareemr.Controller.OutPatientController;
import com.bestray.healthcareemr.Vo.OutPatientDTO;
import com.bestray.healthcareemr.Vo.XrayImage;
import java.awt.CardLayout;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
/**
*
* @author Bestray
*/
public class UploadImagePanel extends SimpleGradientPanel {
/**
* Creates new form UploadXrayImage
*/
public UploadImagePanel() {
initComponents();
populate();
}
public UploadImagePanel(TAppointment appointment) {
initComponents();
populate();
showPreviousImage(appointment);
}
/**
* 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() {
jXTitledPanel1 = new org.jdesktop.swingx.JXTitledPanel();
jPanel1 = new javax.swing.JPanel();
xrayImagePanel = new javax.swing.JPanel();
jToolBar1 = new javax.swing.JToolBar();
previousbutton = new javax.swing.JButton();
nextbutton = new javax.swing.JButton();
upload_btutton = new javax.swing.JButton();
viewLargeSize_bt = new javax.swing.JButton();
setOpaque(false);
setPreferredSize(new java.awt.Dimension(1284, 507));
jPanel1.setOpaque(false);
jPanel1.setLayout(new java.awt.BorderLayout());
xrayImagePanel.setBackground(new java.awt.Color(255, 255, 255));
xrayImagePanel.setLayout(new java.awt.CardLayout());
jPanel1.add(xrayImagePanel, java.awt.BorderLayout.CENTER);
jToolBar1.setBackground(new java.awt.Color(255, 204, 204));
jToolBar1.setFloatable(false);
jToolBar1.setRollover(true);
previousbutton.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
previousbutton.setText("\u22b2Previous");
previousbutton.setFocusable(false);
previousbutton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
previousbutton.setMargin(new java.awt.Insets(2, 20, 2, 20));
previousbutton.setOpaque(false);
previousbutton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
previousbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
previousbuttonActionPerformed(evt);
}
});
jToolBar1.add(previousbutton);
nextbutton.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
nextbutton.setText("Next\u22b3");
nextbutton.setFocusable(false);
nextbutton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
nextbutton.setMargin(new java.awt.Insets(2, 20, 2, 20));
nextbutton.setOpaque(false);
nextbutton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
nextbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextbuttonActionPerformed(evt);
}
});
jToolBar1.add(nextbutton);
upload_btutton.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
upload_btutton.setText("Upload");
upload_btutton.setMargin(new java.awt.Insets(2, 16, 2, 16));
upload_btutton.setOpaque(false);
upload_btutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
upload_btuttonActionPerformed(evt);
}
});
jToolBar1.add(upload_btutton);
viewLargeSize_bt.setFont(new java.awt.Font("SansSerif", 1, 11)); // NOI18N
viewLargeSize_bt.setOpaque(false);
viewLargeSize_bt.setText("View Large Size");
viewLargeSize_bt.setMargin(new java.awt.Insets(2, 16, 2, 16));
viewLargeSize_bt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
viewLargeSize_btActionPerformed(evt);
}
});
jToolBar1.add(viewLargeSize_bt);
jPanel1.add(jToolBar1, java.awt.BorderLayout.PAGE_START);
javax.swing.GroupLayout jXTitledPanel1Layout = new javax.swing.GroupLayout(jXTitledPanel1.getContentContainer());
jXTitledPanel1.getContentContainer().setLayout(jXTitledPanel1Layout);
jXTitledPanel1Layout.setHorizontalGroup(
jXTitledPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 1260, Short.MAX_VALUE)
);
jXTitledPanel1Layout.setVerticalGroup(
jXTitledPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jXTitledPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jXTitledPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(53, 53, 53))
);
}// </editor-fold>//GEN-END:initComponents
private void upload_btuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upload_btuttonActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
filename=new String[50];
j=0;
int res = chooser.showOpenDialog(this);
if (res == JFileChooser.APPROVE_OPTION) {
File[] f = chooser.getSelectedFiles();
for(int i=0;i<f.length;i++){
if (f[i] == null) {
return;
}else{
filename[j] = f[i].getAbsolutePath();
filenamelist.add(filename[j]);
j++;
}
}
SwingWorker sw = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
//Thread.sleep(2000);//simulate large image takes long to load
for(int i=0;i<filename.length;i++){
ii = new ImageIcon(scaleImage(xrayImagePanel.getWidth(), xrayImagePanel.getHeight(), ImageIO.read(new File(filename[i]))));
JPanel j= new JPanel(new java.awt.BorderLayout());
JLabel l = new JLabel();
l.setIcon(ii);
j.add(l);
xrayImagePanel.add(j);
j.repaint();
j.revalidate();
}
return null;
}
};
sw.execute();
}
}//GEN-LAST:event_upload_btuttonActionPerformed
private void viewLargeSize_btActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewLargeSize_btActionPerformed
String[] newFiles = filename;
String[] retievedFiles = retrivefilename;
List<String> list = new ArrayList<String>();
for(String s : newFiles) {
if(s != null && s.length() > 0) {
list.add(s);
}
}
if(list.size()==0){
for(String s : retievedFiles) {
if(s != null && s.length() > 0) {
list.add(s);
}
}
}
newFiles = list.toArray(new String[list.size()]);
new PictureZoomFrame(newFiles).setVisible(true);
}//GEN-LAST:event_viewLargeSize_btActionPerformed
private void previousbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previousbuttonActionPerformed
CardLayout c2 = (CardLayout)xrayImagePanel.getLayout();
c2.previous(xrayImagePanel);
}//GEN-LAST:event_previousbuttonActionPerformed
private void nextbuttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextbuttonActionPerformed
CardLayout c1 = (CardLayout)xrayImagePanel.getLayout();
c1.next(xrayImagePanel);
}//GEN-LAST:event_nextbuttonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel jPanel1;
private javax.swing.JToolBar jToolBar1;
private org.jdesktop.swingx.JXTitledPanel jXTitledPanel1;
private javax.swing.JButton nextbutton;
private javax.swing.JButton previousbutton;
private javax.swing.JButton upload_btutton;
private javax.swing.JButton viewLargeSize_bt;
private javax.swing.JPanel xrayImagePanel;
// End of variables declaration//GEN-END:variables
private OutPatientController outPatientController;
OutPatientDTO xrayimagedto;
private String[] filename=new String[50];
private int j=0;
private List<String> filenamelist = new ArrayList<String>();
private ImageIcon ii;
private Properties properties ;
private String[] retrivefilename=new String[50];
public static BufferedImage scaleImage(int w, int h, BufferedImage img) throws Exception {
BufferedImage bi;
bi = new BufferedImage(w, h, BufferedImage.TRANSLUCENT);
Graphics2D g2d = (Graphics2D) bi.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
g2d.drawImage(img, 0, 0, w, h, null);
g2d.dispose();
return bi;
}
private void populate(){
try {
properties = new Properties();
outPatientController = (OutPatientController)HealthcareLogin.context.getBean("outPatientController");
properties.load(getClass().getResourceAsStream("/system.properties"));
} catch (Exception ex) {
Logger.getLogger(UploadImagePanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
OutPatientDTO setxrayimagedata() {
xrayimagedto = new OutPatientDTO();
xrayimagedto.setFilenamelist(filenamelist);
return xrayimagedto;
}
private void showPreviousImage(TAppointment appointment) {
try {
TPatientEncounter enc =outPatientController.getEncounterByAppoitment(appointment);
List<XrayImage> xrayimagelist = outPatientController.getXrayImages(enc);
retrivefilename=new String[xrayimagelist.size()];
int index=0;
for(XrayImage t:xrayimagelist){
retrivefilename[index] = properties.getProperty("xrayimagepath")+t.getImageName();
index++;
}
for(int i=0;i<retrivefilename.length;i++){
ii = new ImageIcon(scaleImage(1150, 350, ImageIO.read(new File(retrivefilename[i]))));
JPanel j= new JPanel(new java.awt.BorderLayout());
JLabel l = new JLabel();
l.setIcon(ii);
j.add(l);
xrayImagePanel.add(j);
j.repaint();
j.revalidate();
}
}catch (Exception ex) {
Logger.getLogger(UploadImagePanel.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
|