1039 lines
32 KiB
Java
1039 lines
32 KiB
Java
package org.hwo.pulscounter.ui;
|
||
|
||
import java.awt.EventQueue;
|
||
|
||
import javax.swing.DesktopManager;
|
||
import javax.swing.JFileChooser;
|
||
import javax.swing.JFrame;
|
||
import javax.swing.JMenuItem;
|
||
import javax.swing.JPanel;
|
||
import javax.swing.JPopupMenu;
|
||
import javax.swing.Timer;
|
||
|
||
import java.awt.BorderLayout;
|
||
|
||
import javax.swing.JButton;
|
||
|
||
import java.awt.Desktop;
|
||
import java.awt.GridBagLayout;
|
||
import java.awt.GridBagConstraints;
|
||
|
||
import javax.swing.JLabel;
|
||
import javax.swing.JComboBox;
|
||
|
||
import org.hwo.beacon.Beacon;
|
||
import org.hwo.beacon.Beacon.BeaconSender;
|
||
import org.hwo.bitfields.BitField;
|
||
import org.hwo.csv.CSV;
|
||
import org.hwo.io.SerialPort;
|
||
import org.hwo.io.SerialPortExeption;
|
||
import org.hwo.models.TableMapper.AbstractTableMapperListener;
|
||
import org.hwo.models.TableMapper.TableMapper;
|
||
import org.hwo.pulscounter.CounterChannel;
|
||
import org.hwo.pulscounter.IPulsCounter;
|
||
import org.hwo.pulscounter.NewPulsCounterDevice;
|
||
import org.hwo.pulscounter.PulsCounter;
|
||
import org.hwo.pulscounter.TimeBarrier;
|
||
import org.hwo.pulscounter.service.PulsCounterService;
|
||
import org.hwo.rpc.simple.SimpleRPCService;
|
||
import org.hwo.ui.JObjectSelector;
|
||
import org.hwo.ui.MousePopupListener;
|
||
|
||
import java.awt.Insets;
|
||
import java.util.ArrayList;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
import java.util.Properties;
|
||
import java.util.UUID;
|
||
import java.util.prefs.BackingStoreException;
|
||
import java.util.prefs.Preferences;
|
||
|
||
import javax.swing.JTable;
|
||
import javax.swing.JScrollPane;
|
||
|
||
import java.awt.event.ActionListener;
|
||
import java.awt.event.ActionEvent;
|
||
import java.awt.event.MouseAdapter;
|
||
import java.awt.event.MouseEvent;
|
||
|
||
import javax.swing.border.TitledBorder;
|
||
import javax.swing.JSpinner;
|
||
import javax.swing.SpinnerNumberModel;
|
||
import javax.swing.border.BevelBorder;
|
||
import javax.swing.SwingConstants;
|
||
import javax.swing.event.ChangeListener;
|
||
import javax.swing.event.ChangeEvent;
|
||
import javax.swing.JTabbedPane;
|
||
import javax.swing.BoxLayout;
|
||
|
||
import java.awt.event.WindowAdapter;
|
||
import java.awt.event.WindowEvent;
|
||
import java.io.Console;
|
||
import java.io.File;
|
||
import java.io.FileInputStream;
|
||
import java.io.FileNotFoundException;
|
||
import java.io.FileOutputStream;
|
||
import java.io.IOException;
|
||
import java.net.InetAddress;
|
||
import java.net.UnknownHostException;
|
||
|
||
import org.hwo.datetime.JTimeOfDay;
|
||
|
||
import javax.swing.JTextField;
|
||
import javax.swing.JRadioButton;
|
||
import javax.swing.JCheckBox;
|
||
|
||
public class PulsCounterWindow extends JFrame{
|
||
|
||
Beacon clientBeacon;
|
||
IPulsCounter connectedPulsCounter;
|
||
UUID selectedNetworkUUID;
|
||
|
||
boolean useUSB;
|
||
boolean useNetwork;
|
||
|
||
|
||
private JTable tCounter;
|
||
|
||
private TableMapper tmCounter;
|
||
private Preferences prefs;
|
||
private List<CounterChannel> counterChannels;
|
||
|
||
private final JPanel panel_7 = new JPanel();
|
||
private JLabel lDeviceType;
|
||
private JLabel lDeviceTime;
|
||
private JLabel lActivity;
|
||
|
||
Thread threadUpdater;
|
||
Timer updateTimer;
|
||
private JSpinner spUpdateIntervall;
|
||
|
||
boolean applicationExiting;
|
||
|
||
private JComboBox cbTimeBarriers;
|
||
private JTable tTBChannels;
|
||
private JTimeOfDay todTimebarrier;
|
||
|
||
private TableMapper tmTBChannels;
|
||
private JTextField tfWorkDir;
|
||
|
||
private String workingDirectory;
|
||
private JTextField tfPhysicalInterface;
|
||
private JTextField tfNetworkNode;
|
||
private JRadioButton rbNetwork;
|
||
private JRadioButton rbUSB;
|
||
private JCheckBox cbUSBEnabled;
|
||
private JButton btnNetzwerk;
|
||
private JLabel lInputs;
|
||
|
||
public PulsCounterWindow() {
|
||
addWindowListener(new WindowAdapter() {
|
||
@Override
|
||
public void windowClosing(WindowEvent arg0) {
|
||
applicationExiting = true;
|
||
try {
|
||
prefs.sync();
|
||
} catch (Exception ex){
|
||
System.err.print("Preferences could not be saved.");
|
||
ex.printStackTrace();
|
||
}
|
||
}
|
||
});
|
||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||
setBounds(100, 100, 930, 592);
|
||
setTitle("PulsCounter");
|
||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||
gridBagLayout.columnWidths = new int[]{0, 0};
|
||
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
|
||
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||
gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||
getContentPane().setLayout(gridBagLayout);
|
||
|
||
JPanel panel = new JPanel();
|
||
GridBagConstraints gbc_panel = new GridBagConstraints();
|
||
gbc_panel.insets = new Insets(0, 0, 5, 0);
|
||
gbc_panel.fill = GridBagConstraints.BOTH;
|
||
gbc_panel.gridx = 0;
|
||
gbc_panel.gridy = 0;
|
||
getContentPane().add(panel, gbc_panel);
|
||
GridBagLayout gbl_panel = new GridBagLayout();
|
||
gbl_panel.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
|
||
gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
|
||
gbl_panel.columnWeights = new double[]{1.0, 1.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||
gbl_panel.rowWeights = new double[]{1.0, 1.0, 1.0, 0.0, 1.0, Double.MIN_VALUE};
|
||
panel.setLayout(gbl_panel);
|
||
|
||
JPanel panel_1 = new JPanel();
|
||
panel_1.setBorder(new TitledBorder(null, "Anschluss", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
|
||
gbc_panel_1.gridwidth = 3;
|
||
gbc_panel_1.insets = new Insets(0, 0, 5, 5);
|
||
gbc_panel_1.fill = GridBagConstraints.BOTH;
|
||
gbc_panel_1.gridx = 0;
|
||
gbc_panel_1.gridy = 0;
|
||
panel.add(panel_1, gbc_panel_1);
|
||
GridBagLayout gbl_panel_1 = new GridBagLayout();
|
||
gbl_panel_1.columnWidths = new int[]{0, 0, 0, 0};
|
||
gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0};
|
||
gbl_panel_1.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||
gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||
panel_1.setLayout(gbl_panel_1);
|
||
|
||
rbUSB = new JRadioButton("USB");
|
||
rbUSB.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent arg0) {
|
||
selectUSBConnection();
|
||
}
|
||
});
|
||
GridBagConstraints gbc_rbUSB = new GridBagConstraints();
|
||
gbc_rbUSB.anchor = GridBagConstraints.WEST;
|
||
gbc_rbUSB.insets = new Insets(0, 0, 5, 5);
|
||
gbc_rbUSB.gridx = 0;
|
||
gbc_rbUSB.gridy = 0;
|
||
panel_1.add(rbUSB, gbc_rbUSB);
|
||
|
||
rbNetwork = new JRadioButton("Netzwerk");
|
||
rbNetwork.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent e) {
|
||
selectNetworkConnection();
|
||
}
|
||
});
|
||
|
||
cbUSBEnabled = new JCheckBox("USB Verbindung aktiv");
|
||
cbUSBEnabled.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent e) {
|
||
switchUSBEnabled();
|
||
}
|
||
});
|
||
GridBagConstraints gbc_cbUSBEnabled = new GridBagConstraints();
|
||
gbc_cbUSBEnabled.anchor = GridBagConstraints.EAST;
|
||
gbc_cbUSBEnabled.insets = new Insets(0, 0, 5, 5);
|
||
gbc_cbUSBEnabled.gridx = 1;
|
||
gbc_cbUSBEnabled.gridy = 0;
|
||
panel_1.add(cbUSBEnabled, gbc_cbUSBEnabled);
|
||
GridBagConstraints gbc_rbNetwork = new GridBagConstraints();
|
||
gbc_rbNetwork.anchor = GridBagConstraints.WEST;
|
||
gbc_rbNetwork.insets = new Insets(0, 0, 5, 5);
|
||
gbc_rbNetwork.gridx = 0;
|
||
gbc_rbNetwork.gridy = 1;
|
||
panel_1.add(rbNetwork, gbc_rbNetwork);
|
||
|
||
btnNetzwerk = new JButton("Netzwerk...");
|
||
btnNetzwerk.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent arg0) {
|
||
}
|
||
});
|
||
|
||
tfNetworkNode = new JTextField();
|
||
tfNetworkNode.setEditable(false);
|
||
GridBagConstraints gbc_tfNetworkNode = new GridBagConstraints();
|
||
gbc_tfNetworkNode.insets = new Insets(0, 0, 5, 5);
|
||
gbc_tfNetworkNode.fill = GridBagConstraints.HORIZONTAL;
|
||
gbc_tfNetworkNode.gridx = 1;
|
||
gbc_tfNetworkNode.gridy = 1;
|
||
panel_1.add(tfNetworkNode, gbc_tfNetworkNode);
|
||
tfNetworkNode.setColumns(10);
|
||
GridBagConstraints gbc_btnNetzwerk = new GridBagConstraints();
|
||
gbc_btnNetzwerk.insets = new Insets(0, 0, 5, 0);
|
||
gbc_btnNetzwerk.gridx = 2;
|
||
gbc_btnNetzwerk.gridy = 1;
|
||
panel_1.add(btnNetzwerk, gbc_btnNetzwerk);
|
||
|
||
JLabel lblNewLabel = new JLabel("Schnittstelle:");
|
||
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
|
||
gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
|
||
gbc_lblNewLabel.insets = new Insets(0, 0, 0, 5);
|
||
gbc_lblNewLabel.gridx = 0;
|
||
gbc_lblNewLabel.gridy = 2;
|
||
panel_1.add(lblNewLabel, gbc_lblNewLabel);
|
||
|
||
tfPhysicalInterface = new JTextField();
|
||
tfPhysicalInterface.setEditable(false);
|
||
GridBagConstraints gbc_tfPhysicalInterface = new GridBagConstraints();
|
||
gbc_tfPhysicalInterface.insets = new Insets(0, 0, 0, 5);
|
||
gbc_tfPhysicalInterface.anchor = GridBagConstraints.NORTH;
|
||
gbc_tfPhysicalInterface.fill = GridBagConstraints.HORIZONTAL;
|
||
gbc_tfPhysicalInterface.gridx = 1;
|
||
gbc_tfPhysicalInterface.gridy = 2;
|
||
panel_1.add(tfPhysicalInterface, gbc_tfPhysicalInterface);
|
||
tfPhysicalInterface.setColumns(10);
|
||
|
||
JButton btnWhlen = new JButton("w\u00E4hlen...");
|
||
btnWhlen.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent e) {
|
||
selectPhysicalInterface();
|
||
}
|
||
});
|
||
GridBagConstraints gbc_btnWhlen = new GridBagConstraints();
|
||
gbc_btnWhlen.gridx = 2;
|
||
gbc_btnWhlen.gridy = 2;
|
||
panel_1.add(btnWhlen, gbc_btnWhlen);
|
||
|
||
JPanel panel_2 = new JPanel();
|
||
panel_2.setBorder(new TitledBorder(null, "Einstellungen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||
GridBagConstraints gbc_panel_2 = new GridBagConstraints();
|
||
gbc_panel_2.gridwidth = 2;
|
||
gbc_panel_2.insets = new Insets(0, 0, 5, 0);
|
||
gbc_panel_2.fill = GridBagConstraints.BOTH;
|
||
gbc_panel_2.gridx = 3;
|
||
gbc_panel_2.gridy = 0;
|
||
panel.add(panel_2, gbc_panel_2);
|
||
GridBagLayout gbl_panel_2 = new GridBagLayout();
|
||
gbl_panel_2.columnWidths = new int[]{0, 0, 0, 0};
|
||
gbl_panel_2.rowHeights = new int[]{0, 0, 0};
|
||
gbl_panel_2.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||
gbl_panel_2.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
|
||
panel_2.setLayout(gbl_panel_2);
|
||
|
||
JLabel lblAktualisierungsintervall = new JLabel("Aktualisierungsintervall:");
|
||
GridBagConstraints gbc_lblAktualisierungsintervall = new GridBagConstraints();
|
||
gbc_lblAktualisierungsintervall.anchor = GridBagConstraints.WEST;
|
||
gbc_lblAktualisierungsintervall.insets = new Insets(0, 0, 5, 5);
|
||
gbc_lblAktualisierungsintervall.gridx = 0;
|
||
gbc_lblAktualisierungsintervall.gridy = 0;
|
||
panel_2.add(lblAktualisierungsintervall, gbc_lblAktualisierungsintervall);
|
||
|
||
spUpdateIntervall = new JSpinner();
|
||
spUpdateIntervall.addChangeListener(new ChangeListener() {
|
||
public void stateChanged(ChangeEvent arg0) {
|
||
if (updateTimer != null)
|
||
{
|
||
Integer updateIntervall = (Integer)spUpdateIntervall.getValue();
|
||
updateTimer.stop();
|
||
updateTimer.setDelay(updateIntervall * 1000);
|
||
updateTimer.start();
|
||
|
||
prefs.putInt("update.intervall", updateIntervall);
|
||
try {
|
||
prefs.flush();
|
||
} catch (BackingStoreException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
}
|
||
});
|
||
spUpdateIntervall.setModel(new SpinnerNumberModel(15, 5, 3600, 1));
|
||
GridBagConstraints gbc_spUpdateIntervall = new GridBagConstraints();
|
||
gbc_spUpdateIntervall.gridwidth = 2;
|
||
gbc_spUpdateIntervall.insets = new Insets(0, 0, 5, 0);
|
||
gbc_spUpdateIntervall.anchor = GridBagConstraints.EAST;
|
||
gbc_spUpdateIntervall.gridx = 1;
|
||
gbc_spUpdateIntervall.gridy = 0;
|
||
panel_2.add(spUpdateIntervall, gbc_spUpdateIntervall);
|
||
|
||
JLabel lblArbeitsverzeichnis = new JLabel("Arbeitsverzeichnis:");
|
||
GridBagConstraints gbc_lblArbeitsverzeichnis = new GridBagConstraints();
|
||
gbc_lblArbeitsverzeichnis.anchor = GridBagConstraints.EAST;
|
||
gbc_lblArbeitsverzeichnis.insets = new Insets(0, 0, 0, 5);
|
||
gbc_lblArbeitsverzeichnis.gridx = 0;
|
||
gbc_lblArbeitsverzeichnis.gridy = 1;
|
||
panel_2.add(lblArbeitsverzeichnis, gbc_lblArbeitsverzeichnis);
|
||
|
||
tfWorkDir = new JTextField();
|
||
tfWorkDir.setEditable(false);
|
||
GridBagConstraints gbc_tfWorkDir = new GridBagConstraints();
|
||
gbc_tfWorkDir.insets = new Insets(0, 0, 0, 5);
|
||
gbc_tfWorkDir.anchor = GridBagConstraints.NORTH;
|
||
gbc_tfWorkDir.fill = GridBagConstraints.HORIZONTAL;
|
||
gbc_tfWorkDir.gridx = 1;
|
||
gbc_tfWorkDir.gridy = 1;
|
||
panel_2.add(tfWorkDir, gbc_tfWorkDir);
|
||
tfWorkDir.setColumns(10);
|
||
|
||
JButton btnDurchsuchen = new JButton("durchsuchen...");
|
||
btnDurchsuchen.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent arg0) {
|
||
|
||
JFileChooser jfc = new JFileChooser();
|
||
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||
|
||
if (jfc.showOpenDialog(PulsCounterWindow.this)==JFileChooser.APPROVE_OPTION)
|
||
{
|
||
workingDirectory = jfc.getSelectedFile().getAbsolutePath();
|
||
tfWorkDir.setText(workingDirectory);
|
||
prefs.put("file.directory",workingDirectory);
|
||
try {
|
||
prefs.flush();
|
||
} catch (BackingStoreException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
}
|
||
});
|
||
GridBagConstraints gbc_btnDurchsuchen = new GridBagConstraints();
|
||
gbc_btnDurchsuchen.gridx = 2;
|
||
gbc_btnDurchsuchen.gridy = 1;
|
||
panel_2.add(btnDurchsuchen, gbc_btnDurchsuchen);
|
||
|
||
JPanel panel_3 = new JPanel();
|
||
panel_3.setBorder(new TitledBorder(null, "Aktionen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||
GridBagConstraints gbc_panel_3 = new GridBagConstraints();
|
||
gbc_panel_3.gridwidth = 5;
|
||
gbc_panel_3.insets = new Insets(0, 0, 5, 5);
|
||
gbc_panel_3.fill = GridBagConstraints.BOTH;
|
||
gbc_panel_3.gridx = 0;
|
||
gbc_panel_3.gridy = 3;
|
||
panel.add(panel_3, gbc_panel_3);
|
||
GridBagLayout gbl_panel_3 = new GridBagLayout();
|
||
gbl_panel_3.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||
gbl_panel_3.rowHeights = new int[]{0, 0};
|
||
gbl_panel_3.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||
gbl_panel_3.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||
panel_3.setLayout(gbl_panel_3);
|
||
|
||
JButton btnNewButton = new JButton("Jetzt aktualisieren...");
|
||
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
|
||
gbc_btnNewButton.insets = new Insets(0, 0, 0, 5);
|
||
gbc_btnNewButton.gridx = 1;
|
||
gbc_btnNewButton.gridy = 0;
|
||
panel_3.add(btnNewButton, gbc_btnNewButton);
|
||
|
||
JButton btnAlle = new JButton("Alle 0");
|
||
btnAlle.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent arg0) {
|
||
|
||
resetAllChannels();
|
||
|
||
synchronized (threadUpdater) {
|
||
threadUpdater.notifyAll();
|
||
}
|
||
}
|
||
});
|
||
GridBagConstraints gbc_btnAlle = new GridBagConstraints();
|
||
gbc_btnAlle.insets = new Insets(0, 0, 0, 5);
|
||
gbc_btnAlle.gridx = 3;
|
||
gbc_btnAlle.gridy = 0;
|
||
panel_3.add(btnAlle, gbc_btnAlle);
|
||
|
||
JButton btnInspektor = new JButton("Inspektor");
|
||
btnInspektor.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent e) {
|
||
InspectionMainFrame f = new InspectionMainFrame();
|
||
f.setVisible(true);
|
||
}
|
||
});
|
||
GridBagConstraints gbc_btnInspektor = new GridBagConstraints();
|
||
gbc_btnInspektor.insets = new Insets(0, 0, 0, 5);
|
||
gbc_btnInspektor.gridx = 17;
|
||
gbc_btnInspektor.gridy = 0;
|
||
panel_3.add(btnInspektor, gbc_btnInspektor);
|
||
btnNewButton.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent arg0) {
|
||
synchronized (threadUpdater) {
|
||
threadUpdater.notifyAll();
|
||
}
|
||
}
|
||
});
|
||
|
||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||
GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
|
||
gbc_tabbedPane.insets = new Insets(0, 0, 5, 0);
|
||
gbc_tabbedPane.fill = GridBagConstraints.BOTH;
|
||
gbc_tabbedPane.gridx = 0;
|
||
gbc_tabbedPane.gridy = 1;
|
||
getContentPane().add(tabbedPane, gbc_tabbedPane);
|
||
|
||
JPanel panel_8 = new JPanel();
|
||
tabbedPane.addTab("Aktuelle Werte", null, panel_8, null);
|
||
panel_8.setLayout(new BoxLayout(panel_8, BoxLayout.X_AXIS));
|
||
|
||
JScrollPane scrollPane = new JScrollPane();
|
||
panel_8.add(scrollPane);
|
||
|
||
tCounter = new JTable();
|
||
scrollPane.setViewportView(tCounter);
|
||
|
||
JPanel panel_9 = new JPanel();
|
||
tabbedPane.addTab("Tageszeiterfassung", null, panel_9, null);
|
||
GridBagLayout gbl_panel_9 = new GridBagLayout();
|
||
gbl_panel_9.columnWidths = new int[]{0, 0, 0};
|
||
gbl_panel_9.rowHeights = new int[]{0, 0, 0, 0};
|
||
gbl_panel_9.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||
gbl_panel_9.rowWeights = new double[]{0.0, 0.0, 1.0, Double.MIN_VALUE};
|
||
panel_9.setLayout(gbl_panel_9);
|
||
|
||
JLabel lblNewLabel_1 = new JLabel("Speicher:");
|
||
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||
gbc_lblNewLabel_1.anchor = GridBagConstraints.WEST;
|
||
gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
|
||
gbc_lblNewLabel_1.gridx = 0;
|
||
gbc_lblNewLabel_1.gridy = 0;
|
||
panel_9.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||
|
||
cbTimeBarriers = new JComboBox();
|
||
cbTimeBarriers.addActionListener(new ActionListener() {
|
||
public void actionPerformed(ActionEvent arg0) {
|
||
updateTimeBarrierView();
|
||
}
|
||
});
|
||
GridBagConstraints gbc_cbTimeBarriers = new GridBagConstraints();
|
||
gbc_cbTimeBarriers.insets = new Insets(0, 0, 5, 0);
|
||
gbc_cbTimeBarriers.fill = GridBagConstraints.HORIZONTAL;
|
||
gbc_cbTimeBarriers.gridx = 1;
|
||
gbc_cbTimeBarriers.gridy = 0;
|
||
panel_9.add(cbTimeBarriers, gbc_cbTimeBarriers);
|
||
|
||
JPanel panel_10 = new JPanel();
|
||
panel_10.setBorder(new TitledBorder(null, "Einstellungen", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||
GridBagConstraints gbc_panel_10 = new GridBagConstraints();
|
||
gbc_panel_10.insets = new Insets(0, 0, 5, 0);
|
||
gbc_panel_10.gridwidth = 2;
|
||
gbc_panel_10.fill = GridBagConstraints.BOTH;
|
||
gbc_panel_10.gridx = 0;
|
||
gbc_panel_10.gridy = 1;
|
||
panel_9.add(panel_10, gbc_panel_10);
|
||
GridBagLayout gbl_panel_10 = new GridBagLayout();
|
||
gbl_panel_10.columnWidths = new int[]{0, 0, 0};
|
||
gbl_panel_10.rowHeights = new int[]{0, 0};
|
||
gbl_panel_10.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
|
||
gbl_panel_10.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||
panel_10.setLayout(gbl_panel_10);
|
||
|
||
JLabel lblDdd = new JLabel("Werte erfassen bis:");
|
||
GridBagConstraints gbc_lblDdd = new GridBagConstraints();
|
||
gbc_lblDdd.anchor = GridBagConstraints.WEST;
|
||
gbc_lblDdd.insets = new Insets(0, 0, 0, 5);
|
||
gbc_lblDdd.fill = GridBagConstraints.VERTICAL;
|
||
gbc_lblDdd.gridx = 0;
|
||
gbc_lblDdd.gridy = 0;
|
||
panel_10.add(lblDdd, gbc_lblDdd);
|
||
|
||
todTimebarrier = new JTimeOfDay();
|
||
todTimebarrier.setSecondsHidden(true);
|
||
todTimebarrier.addChangeListener(new ChangeListener() {
|
||
public void stateChanged(ChangeEvent e) {
|
||
repaint();
|
||
}
|
||
});
|
||
GridBagConstraints gbc_todTimebarrier = new GridBagConstraints();
|
||
gbc_todTimebarrier.anchor = GridBagConstraints.WEST;
|
||
gbc_todTimebarrier.fill = GridBagConstraints.VERTICAL;
|
||
gbc_todTimebarrier.gridx = 1;
|
||
gbc_todTimebarrier.gridy = 0;
|
||
panel_10.add(todTimebarrier, gbc_todTimebarrier);
|
||
|
||
JPanel panel_11 = new JPanel();
|
||
panel_11.setBorder(new TitledBorder(null, "Aktuelle Werte", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||
GridBagConstraints gbc_panel_11 = new GridBagConstraints();
|
||
gbc_panel_11.gridwidth = 2;
|
||
gbc_panel_11.fill = GridBagConstraints.BOTH;
|
||
gbc_panel_11.gridx = 0;
|
||
gbc_panel_11.gridy = 2;
|
||
panel_9.add(panel_11, gbc_panel_11);
|
||
GridBagLayout gbl_panel_11 = new GridBagLayout();
|
||
gbl_panel_11.columnWidths = new int[]{0, 0};
|
||
gbl_panel_11.rowHeights = new int[]{0, 0};
|
||
gbl_panel_11.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||
gbl_panel_11.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||
panel_11.setLayout(gbl_panel_11);
|
||
|
||
JScrollPane scrollPane_1 = new JScrollPane();
|
||
GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints();
|
||
gbc_scrollPane_1.fill = GridBagConstraints.BOTH;
|
||
gbc_scrollPane_1.gridx = 0;
|
||
gbc_scrollPane_1.gridy = 0;
|
||
panel_11.add(scrollPane_1, gbc_scrollPane_1);
|
||
|
||
tTBChannels = new JTable();
|
||
scrollPane_1.setViewportView(tTBChannels);
|
||
|
||
JPanel panel_4 = new JPanel();
|
||
GridBagConstraints gbc_panel_4 = new GridBagConstraints();
|
||
gbc_panel_4.fill = GridBagConstraints.BOTH;
|
||
gbc_panel_4.gridx = 0;
|
||
gbc_panel_4.gridy = 2;
|
||
getContentPane().add(panel_4, gbc_panel_4);
|
||
GridBagLayout gbl_panel_4 = new GridBagLayout();
|
||
gbl_panel_4.columnWidths = new int[]{0, 0, 0, 0, 0};
|
||
gbl_panel_4.rowHeights = new int[]{0, 0};
|
||
gbl_panel_4.columnWeights = new double[]{1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||
gbl_panel_4.rowWeights = new double[]{0.0, Double.MIN_VALUE};
|
||
panel_4.setLayout(gbl_panel_4);
|
||
|
||
JPanel panel_6 = new JPanel();
|
||
panel_6.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
||
GridBagConstraints gbc_panel_6 = new GridBagConstraints();
|
||
gbc_panel_6.insets = new Insets(0, 0, 0, 5);
|
||
gbc_panel_6.fill = GridBagConstraints.BOTH;
|
||
gbc_panel_6.gridx = 0;
|
||
gbc_panel_6.gridy = 0;
|
||
panel_4.add(panel_6, gbc_panel_6);
|
||
GridBagLayout gbl_panel_6 = new GridBagLayout();
|
||
gbl_panel_6.columnWidths = new int[]{348, 0};
|
||
gbl_panel_6.rowHeights = new int[]{16, 0};
|
||
gbl_panel_6.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
||
gbl_panel_6.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
||
panel_6.setLayout(gbl_panel_6);
|
||
|
||
lActivity = new JLabel("Verbindungsaktivit\u00E4t");
|
||
lActivity.setToolTipText("Aktuelle Aufgabe");
|
||
lActivity.setHorizontalAlignment(SwingConstants.LEFT);
|
||
GridBagConstraints gbc_lActivity = new GridBagConstraints();
|
||
gbc_lActivity.insets = new Insets(0, 5, 0, 0);
|
||
gbc_lActivity.anchor = GridBagConstraints.WEST;
|
||
gbc_lActivity.gridx = 0;
|
||
gbc_lActivity.gridy = 0;
|
||
panel_6.add(lActivity, gbc_lActivity);
|
||
|
||
lInputs = new JLabel("Input State");
|
||
GridBagConstraints gbc_lInputs = new GridBagConstraints();
|
||
gbc_lInputs.insets = new Insets(0, 0, 0, 5);
|
||
gbc_lInputs.gridx = 1;
|
||
gbc_lInputs.gridy = 0;
|
||
panel_4.add(lInputs, gbc_lInputs);
|
||
|
||
JPanel panel_5 = new JPanel();
|
||
panel_5.setToolTipText("Angeschlossener Ger\u00E4tetyp");
|
||
panel_5.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
||
GridBagConstraints gbc_panel_5 = new GridBagConstraints();
|
||
gbc_panel_5.insets = new Insets(0, 0, 0, 5);
|
||
gbc_panel_5.fill = GridBagConstraints.VERTICAL;
|
||
gbc_panel_5.gridx = 2;
|
||
gbc_panel_5.gridy = 0;
|
||
panel_4.add(panel_5, gbc_panel_5);
|
||
|
||
lDeviceType = new JLabel("----");
|
||
panel_5.add(lDeviceType);
|
||
GridBagConstraints gbc_panel_7 = new GridBagConstraints();
|
||
gbc_panel_7.gridx = 3;
|
||
gbc_panel_7.gridy = 0;
|
||
panel_7.setToolTipText("Ger\u00E4tezeit bei letztem Kontakt");
|
||
panel_4.add(panel_7, gbc_panel_7);
|
||
panel_7.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
||
|
||
lDeviceTime = new JLabel("----");
|
||
panel_7.add(lDeviceTime);
|
||
|
||
|
||
initialize();
|
||
}
|
||
|
||
private void initialize() {
|
||
|
||
clientBeacon = new Beacon(44556);
|
||
clientBeacon.setClientOnly(true);
|
||
clientBeacon.start();
|
||
|
||
applicationExiting = false;
|
||
|
||
prefs = Preferences.userRoot();
|
||
|
||
workingDirectory = prefs.get("file.directory", (new File(".")).getAbsolutePath());
|
||
tfWorkDir.setText(workingDirectory);
|
||
|
||
counterChannels = new ArrayList<CounterChannel>();
|
||
|
||
tmCounter = new TableMapper(CounterChannel.class, tCounter);
|
||
tmCounter.getColumnInfo().get(0).setReadOnly(true);
|
||
tmCounter.getColumnInfo().get(2).setReadOnly(true);
|
||
tmCounter.getColumnInfo().get(4).setReadOnly(true);
|
||
|
||
tmCounter.addTableMapperListener(new AbstractTableMapperListener() {
|
||
@Override
|
||
public void ValueChanged(int row, int column) {
|
||
switch (column)
|
||
{
|
||
case 1:
|
||
saveChannelName(row);
|
||
break;
|
||
case 3:
|
||
saveCorrection(row);
|
||
break;
|
||
}
|
||
}
|
||
|
||
});
|
||
|
||
tCounter.addMouseListener(new MousePopupListener() {
|
||
|
||
@Override
|
||
public void popupTriggered(int x, int y) {
|
||
JPopupMenu popup = new JPopupMenu();
|
||
JMenuItem mi = new JMenuItem();
|
||
mi.setText("RESET");
|
||
mi.addActionListener(new ActionListener() {
|
||
|
||
@Override
|
||
public void actionPerformed(ActionEvent arg0) {
|
||
CounterChannel cc = (CounterChannel)tmCounter.getSelectedRow();
|
||
if (cc != null)
|
||
{
|
||
try {
|
||
connectedPulsCounter.setChannelCounter(cc.getChannel(), 0);
|
||
} catch (SerialPortExeption sex){
|
||
System.err.println(sex);
|
||
sex.printStackTrace();
|
||
}
|
||
|
||
synchronized (threadUpdater) {
|
||
threadUpdater.notifyAll();
|
||
}
|
||
}
|
||
|
||
}
|
||
});
|
||
popup.add(mi);
|
||
|
||
popup.show(tCounter, x, y);
|
||
|
||
}
|
||
});
|
||
|
||
tmTBChannels = new TableMapper(CounterChannel.class, tTBChannels);
|
||
tmTBChannels.getColumnInfo().get(0).setReadOnly(true);
|
||
tmTBChannels.getColumnInfo().get(1).setReadOnly(true);
|
||
tmTBChannels.getColumnInfo().get(3).setReadOnly(true);
|
||
|
||
threadUpdater = new Thread(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
while (true)
|
||
{
|
||
if (applicationExiting)
|
||
return;
|
||
|
||
try {
|
||
synchronized (threadUpdater) {
|
||
threadUpdater.wait();
|
||
}
|
||
updateCounter();
|
||
// updateLiveFile();
|
||
} catch (InterruptedException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
}
|
||
});
|
||
threadUpdater.start();
|
||
|
||
spUpdateIntervall.setValue(prefs.getInt("update.intervall", 15));
|
||
updateTimer = new Timer(prefs.getInt("update.intervall", 15)*1000, new ActionListener() {
|
||
|
||
@Override
|
||
public void actionPerformed(ActionEvent arg0) {
|
||
synchronized (threadUpdater) {
|
||
threadUpdater.notifyAll();
|
||
}
|
||
|
||
}
|
||
});
|
||
updateTimer.setRepeats(true);
|
||
updateTimer.start();
|
||
|
||
|
||
useUSB = prefs.getBoolean("pulscounter.ui.useUSB", false);
|
||
useNetwork = prefs.getBoolean("pulscounter.ui.useNetwork", false);
|
||
|
||
|
||
|
||
updateUI();
|
||
setupDeviceConnection();
|
||
}
|
||
|
||
private void updateCounter()
|
||
{
|
||
lActivity.setText("Werte aktualisieren...");
|
||
System.err.println("Werte aktualisieren...");
|
||
|
||
if (counterChannels == null)
|
||
{
|
||
tmCounter.setRows(counterChannels);
|
||
}
|
||
|
||
IPulsCounter ipc = connectedPulsCounter;
|
||
|
||
if (ipc == null)
|
||
return;
|
||
|
||
int nch = 0;
|
||
int[] counters = null;
|
||
Integer inputs = -1;
|
||
|
||
try {
|
||
nch = ipc.getChannels();
|
||
counters = ipc.getChannelCounters();
|
||
inputs = ipc.getPhysicalInputs();
|
||
} catch (SerialPortExeption sex){
|
||
System.err.println("GUI: updateCounter(): SerialPortException: " + sex.toString());
|
||
sex.printStackTrace();
|
||
}
|
||
|
||
System.err.println(String.format("GUI: updateCounter(): Channel Array Size: %d / %d",nch,counterChannels.size()));
|
||
|
||
lInputs.setText(new BitField().toText(inputs));
|
||
|
||
if (nch != counterChannels.size()){
|
||
counterChannels.clear();
|
||
|
||
for (int i=0;i<nch;i++){
|
||
counterChannels.add(new CounterChannel(i));
|
||
}
|
||
|
||
loadChannelNames();
|
||
loadChannelOffsets();
|
||
|
||
tmCounter.setRows(counterChannels);
|
||
}
|
||
|
||
for (CounterChannel channel: counterChannels){
|
||
channel.setValue(counters[channel.getChannel()]);
|
||
}
|
||
|
||
lActivity.setText("warten...");
|
||
tCounter.repaint();
|
||
}
|
||
|
||
private void saveCorrection(int row)
|
||
{
|
||
try {
|
||
System.err.println(String.format("Korrekturwert f<>r Kanal %d = %d",row + 1,tmCounter.getRow(row,CounterChannel.class).getCorrect()));
|
||
connectedPulsCounter.setChannelOffset(row, tmCounter.getRow(row,CounterChannel.class).getCorrect());
|
||
} catch (SerialPortExeption sex){
|
||
System.err.println("GUI: saveCorrection(): SerialPortException: " + sex.toString());
|
||
sex.printStackTrace();
|
||
}
|
||
}
|
||
|
||
private void saveChannelName(int channel)
|
||
{
|
||
try {
|
||
connectedPulsCounter.setChannelName(channel, counterChannels.get(channel).getBezeichnung());
|
||
} catch (SerialPortExeption sex){
|
||
System.err.println("GUI: saveChannelName(): SerialPortException: " + sex.toString());
|
||
sex.printStackTrace();
|
||
}
|
||
|
||
}
|
||
private void loadChannelNames()
|
||
{
|
||
for (CounterChannel channel: counterChannels){
|
||
try {
|
||
channel.setBezeichnung(connectedPulsCounter.getChannelName(channel.getChannel()));
|
||
} catch (SerialPortExeption sex){
|
||
System.err.println("GUI: loadChannelNames(): SerialPortException: " + sex.toString());
|
||
sex.printStackTrace();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void loadChannelOffsets() {
|
||
|
||
try {
|
||
int[] offsets = connectedPulsCounter.getChannelOffsets();
|
||
|
||
if (offsets.length != counterChannels.size()) {
|
||
System.err.println(String.format("GUI: loadChannelOffsets(): offset list size differs: %d != %d",offsets.length,counterChannels.size()));
|
||
}
|
||
for (CounterChannel channel: counterChannels){
|
||
channel.setCorrect(offsets[channel.getChannel()]);
|
||
}
|
||
} catch (SerialPortExeption sex){
|
||
System.err.println("GUI: loadChannelOffsets(): SerialPortException: " + sex.toString());
|
||
sex.printStackTrace();
|
||
}
|
||
}
|
||
|
||
private void resetAllChannels() {
|
||
for (CounterChannel channel: counterChannels){
|
||
try {
|
||
connectedPulsCounter.setChannelCounter(channel.getChannel(), 0);
|
||
} catch (SerialPortExeption sex){
|
||
System.err.println("GUI: resetAllChannels(): SerialPortException: " + sex.toString());
|
||
sex.printStackTrace();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
public void updateTimeBarrierView()
|
||
{
|
||
TimeBarrier tb = (TimeBarrier)cbTimeBarriers.getSelectedItem();
|
||
if (tb == null)
|
||
{
|
||
todTimebarrier.setEnabled(false);
|
||
tTBChannels.setEnabled(false);
|
||
} else
|
||
{
|
||
todTimebarrier.setEnabled(true);
|
||
todTimebarrier.setTimeOfDay(tb.getTimeOfDay());
|
||
}
|
||
}
|
||
|
||
public void updateLiveFile()
|
||
{
|
||
/* Date date = new Date();
|
||
|
||
CSV csv = new CSV();
|
||
|
||
for (int n=0;n<pulsCounterDevice.getChannels().size();n++)
|
||
{
|
||
String[] row = new String[4];
|
||
|
||
row[0] = (new Integer(n+1)).toString();
|
||
row[1] = pulsCounterDevice.getChannels().get(n).getValue().toString();
|
||
row[2] = pulsCounterDevice.getChannels().get(n).getCorrect().toString();
|
||
row[3] = pulsCounterDevice.getChannels().get(n).correctedValue().toString();
|
||
|
||
csv.getCells().add(row);
|
||
}
|
||
|
||
csv.saveToFile(String.format("%s/live.csv",workingDirectory));
|
||
*/
|
||
}
|
||
|
||
private void selectPhysicalInterface(){
|
||
try {
|
||
String pn = (String)JObjectSelector.execute(connectedPulsCounter.getPhysicalInterfaceNames());
|
||
connectedPulsCounter.setPhysicalInterfaceName(pn);
|
||
tfPhysicalInterface.setText(pn);
|
||
} catch (SerialPortExeption sex){
|
||
System.err.println("GUI: setPhysicalInterface(): SerialPortException: " + sex.toString());
|
||
sex.printStackTrace();
|
||
}
|
||
|
||
}
|
||
|
||
|
||
private synchronized void changeDeviceConnection(IPulsCounter ipc){
|
||
try {
|
||
counterChannels.clear();
|
||
connectedPulsCounter = ipc;
|
||
if (ipc != null){
|
||
tfPhysicalInterface.setText(ipc.getPhysicalInterfaceName());
|
||
} else {
|
||
tfPhysicalInterface.setText("");
|
||
}
|
||
} catch (SerialPortExeption sex){
|
||
System.err.println("GUI: changeDeviceConnection(): SerialPortException: " + sex.toString());
|
||
sex.printStackTrace();
|
||
}
|
||
|
||
}
|
||
private void selectUSBConnection(){
|
||
useUSB = true;
|
||
useNetwork = false;
|
||
|
||
setupDeviceConnection();
|
||
updateUI();
|
||
}
|
||
|
||
private void selectNetworkConnection(){
|
||
useUSB = false;
|
||
useNetwork = true;
|
||
|
||
if (selectedNetworkUUID == null) {
|
||
|
||
selectedNetworkUUID = selectNetworkNode();
|
||
|
||
if (selectedNetworkUUID == null) {
|
||
useNetwork = false;
|
||
}
|
||
}
|
||
|
||
setupDeviceConnection();
|
||
updateUI();
|
||
|
||
}
|
||
|
||
private void switchUSBEnabled(){
|
||
PulsCounterService localService = PulsCounter.getLocalService();
|
||
if (localService.isActive()){
|
||
useUSB = false;
|
||
localService.stop();
|
||
prefs.putBoolean("pulscounter.local.enabled", false);
|
||
} else {
|
||
localService.start();
|
||
prefs.putBoolean("pulscounter.local.enabled", true);
|
||
}
|
||
|
||
setupDeviceConnection();
|
||
updateUI();
|
||
|
||
try {
|
||
prefs.sync();
|
||
} catch (BackingStoreException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
private UUID selectNetworkNode(){
|
||
BeaconSender sender = NetworkSelectorDialog.show(clientBeacon);
|
||
if (sender != null){
|
||
return UUID.fromString(sender.getProperties().getProperty("beacon.uuid"));
|
||
}
|
||
return null;
|
||
}
|
||
|
||
private void setupDeviceConnection(){
|
||
if (useUSB){
|
||
|
||
if (isUSBEnabled()) {
|
||
changeDeviceConnection( PulsCounter.getLocalService().getLocalDevice() );
|
||
} else {
|
||
changeDeviceConnection( null );
|
||
}
|
||
|
||
} else {
|
||
|
||
if (selectedNetworkUUID != null) {
|
||
|
||
BeaconSender sender = clientBeacon.getSenderByUUID(selectedNetworkUUID);
|
||
if (sender != null) {
|
||
IPulsCounter ipc = PulsCounter.createProxyFromBeaconSender(sender);
|
||
|
||
changeDeviceConnection(ipc);
|
||
} else {
|
||
changeDeviceConnection(null);
|
||
}
|
||
} else {
|
||
changeDeviceConnection(null);
|
||
}
|
||
}
|
||
}
|
||
|
||
private boolean isUSBEnabled(){
|
||
return PulsCounter.getLocalService().isActive();
|
||
}
|
||
|
||
private void updateUI() {
|
||
updateUIUsbEnabled(isUSBEnabled());
|
||
rbUSB.setSelected(useUSB);
|
||
rbNetwork.setSelected(useNetwork);
|
||
btnNetzwerk.setEnabled(useNetwork);
|
||
|
||
tfNetworkNode.setText("");
|
||
if (useNetwork){
|
||
if (selectedNetworkUUID != null){
|
||
BeaconSender sender = clientBeacon.getSenderByUUID(selectedNetworkUUID);
|
||
if (sender != null){
|
||
tfNetworkNode.setText(sender.getProperties().getProperty("beacon.name"));
|
||
prefs.put("pulscounter.network.connect.hostname", sender.getProperties().getProperty("beacon.name"));
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
prefs.putBoolean("pulscounter.ui.useUSB", useUSB);
|
||
prefs.putBoolean("pulscounter.ui.useNetwork", useNetwork);
|
||
|
||
}
|
||
|
||
private void updateUIUsbEnabled(boolean enabled){
|
||
cbUSBEnabled.setSelected(enabled);
|
||
rbUSB.setEnabled(enabled);
|
||
if (enabled){
|
||
} else {
|
||
rbUSB.setSelected(false);
|
||
}
|
||
}
|
||
|
||
|
||
}
|