Cashier.java
3.01 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
package org.streamparty.remoterfid;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Cashier extends javax.swing.JPanel {
private static final Logger logger = LoggerFactory.getLogger(Cashier.class);
private String myName;
private RemoteRfidClient myRemote;
public Cashier() {
super();
JButton close = new JButton("Close");
close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
JPanel paneeli = new JPanel(new GridLayout(0, 1));
paneeli.add(close);
paneeli.setVisible(true);
this.add(paneeli);
this.setVisible(true);
try {
logger.debug("Creating Port selector");
new SelectPort(this);
} catch (java.lang.UnsatisfiedLinkError e) {
logger.warn("RXTX library error", e);
throw e;
}
try {
while (true) {
RfidAction inst = RfidAction.getInstance();
if (inst != null) {
String tag = inst.listenPort();
RemoteRfidClient remoteClient;
try {
remoteClient = getRemoteClient();
logger.info("Found tag {}", tag);
if (remoteClient != null) {
remoteClient.foundTag(myName, tag);
}
} catch (Throwable t) {
logger.warn("Caught exception while executing remote command!", t);
myRemote = null;
}
}
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private RemoteRfidClient getRemoteClient() {
if (myRemote == null) {
try {
Registry registry = LocateRegistry.getRegistry("streamparty.lan", RemoteRfidClient.RMI_PORT);
myRemote = (RemoteRfidClient) registry.lookup(RemoteRfidClient.REMOTE_DESCRIPTOR);
logger.info("Created remote listener {}",myRemote);
} catch (RemoteException e1) {
myRemote = null;
e1.printStackTrace();
} catch (NotBoundException e) {
myRemote = null;
e.printStackTrace();
}
}
return myRemote;
}
public JMenuBar menuBar;
public JToolBar toolBar;
/**
*
*/
private static final long serialVersionUID = 1197345710866765672L;
public static void main(String[] vars) {
logger.debug("Libpath " + System.getProperty("java.library.path"));
JFrame frame = new JFrame("Stream cashier software");
frame.setSize(400, 400);
frame.setLocation(300, 200);
frame.setVisible(true);
Cashier cashier = new Cashier();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(cashier.menuBar);
// frame.getContentPane().add(cashier.toolBar);
frame.getContentPane().add(cashier);
logger.debug("Frame set visible");
frame.validate();
return;
}
public void setReaderName(String text) {
myName = text;
}
}