-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCapture.java
More file actions
160 lines (137 loc) · 4.08 KB
/
Capture.java
File metadata and controls
160 lines (137 loc) · 4.08 KB
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
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import com.digitalpersona.uareu.*;
public class Capture
extends JPanel
implements ActionListener
{
private static final long serialVersionUID = 2;
private static final String ACT_BACK = "back";
private JDialog m_dlgParent;
private CaptureThread m_capture;
private Reader m_reader;
private ImagePanel m_image;
private boolean m_bStreaming;
private Capture(Reader reader, boolean bStreaming){
m_reader = reader;
m_bStreaming = bStreaming;
m_capture = new CaptureThread(m_reader, m_bStreaming, Fid.Format.ANSI_381_2004, Reader.ImageProcessing.IMG_PROC_DEFAULT);
final int vgap = 5;
BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
setLayout(layout);
m_image = new ImagePanel();
Dimension dm = new Dimension(380, 380);
m_image.setPreferredSize(dm);
add(m_image);
add(Box.createVerticalStrut(vgap));
JButton btnBack = new JButton("Back");
btnBack.setActionCommand(ACT_BACK);
btnBack.addActionListener(this);
add(btnBack);
add(Box.createVerticalStrut(vgap));
}
private void StartCaptureThread(){
m_capture = new CaptureThread(m_reader, m_bStreaming, Fid.Format.ANSI_381_2004, Reader.ImageProcessing.IMG_PROC_DEFAULT);
m_capture.start(this);
}
private void StopCaptureThread(){
if(null != m_capture) m_capture.cancel();
}
private void WaitForCaptureThread(){
if(null != m_capture) m_capture.join(1000);
}
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals(ACT_BACK)){
//event from "back" button
//cancel capture
StopCaptureThread();
}
else if(e.getActionCommand().equals(CaptureThread.ACT_CAPTURE)){
//event from capture thread
CaptureThread.CaptureEvent evt = (CaptureThread.CaptureEvent)e;
boolean bCanceled = false;
if(null != evt.capture_result){
if(null != evt.capture_result.image && Reader.CaptureQuality.GOOD == evt.capture_result.quality){
//display image
m_image.showImage(evt.capture_result.image);
}
else if(Reader.CaptureQuality.CANCELED == evt.capture_result.quality){
//capture or streaming was canceled, just quit
bCanceled = true;
}
else{
//bad quality
MessageBox.BadQuality(evt.capture_result.quality);
}
}
else if(null != evt.exception){
//exception during capture
MessageBox.DpError("Capture", evt.exception);
bCanceled = true;
}
else if(null != evt.reader_status){
MessageBox.BadStatus(evt.reader_status);
bCanceled = true;
}
if(!bCanceled){
if(!m_bStreaming){
//restart capture thread
WaitForCaptureThread();
StartCaptureThread();
}
}
else{
//destroy dialog
m_dlgParent.setVisible(false);
}
}
}
private void doModal(JDialog dlgParent){
//open reader
try{
m_reader.Open(Reader.Priority.COOPERATIVE);
}
catch(UareUException e){ MessageBox.DpError("Reader.Open()", e); }
boolean bOk = true;
if(m_bStreaming){
//check if streaming supported
Reader.Capabilities rc = m_reader.GetCapabilities();
if(!rc.can_stream){
MessageBox.Warning("This reader does not support streaming");
bOk = false;
}
}
if(bOk){
//start capture thread
StartCaptureThread();
//bring up modal dialog
m_dlgParent = dlgParent;
m_dlgParent.setContentPane(this);
m_dlgParent.pack();
m_dlgParent.setLocationRelativeTo(null);
m_dlgParent.toFront();
m_dlgParent.setVisible(true);
m_dlgParent.dispose();
//cancel capture
StopCaptureThread();
//wait for capture thread to finish
WaitForCaptureThread();
}
//close reader
try{
m_reader.Close();
}
catch(UareUException e){ MessageBox.DpError("Reader.Close()", e); }
}
public static void Run(Reader reader, boolean bStreaming){
JDialog dlg = new JDialog((JDialog)null, "Put your finger on the reader", true);
Capture capture = new Capture(reader, bStreaming);
capture.doModal(dlg);
}
}