780 lines
26 KiB
Java
780 lines
26 KiB
Java
|
package org.hwo.pulscounter;
|
|||
|
|
|||
|
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.csv.CSV;
|
|||
|
import org.hwo.io.SerialPort;
|
|||
|
import org.hwo.models.TableMapper.AbstractTableMapperListener;
|
|||
|
import org.hwo.models.TableMapper.TableMapper;
|
|||
|
import org.hwo.pulscounter.ui.NetworkSelectorDialog;
|
|||
|
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.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.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;
|
|||
|
|
|||
|
public class PulsCounterWindow extends JFrame{
|
|||
|
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 PulsCounterDevice pulsCounterDevice;
|
|||
|
private JComboBox cbTimeBarriers;
|
|||
|
private JTable tTBChannels;
|
|||
|
private JTimeOfDay todTimebarrier;
|
|||
|
|
|||
|
private TableMapper tmTBChannels;
|
|||
|
private JTextField tfWorkDir;
|
|||
|
|
|||
|
private String workingDirectory;
|
|||
|
private JTextField tfPhysicalInterface;
|
|||
|
|
|||
|
public PulsCounterWindow() {
|
|||
|
addWindowListener(new WindowAdapter() {
|
|||
|
@Override
|
|||
|
public void windowClosing(WindowEvent arg0) {
|
|||
|
applicationExiting = true;
|
|||
|
}
|
|||
|
});
|
|||
|
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};
|
|||
|
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, Double.MIN_VALUE};
|
|||
|
panel_1.setLayout(gbl_panel_1);
|
|||
|
|
|||
|
JButton btnNetzwerk = new JButton("Netzwerk...");
|
|||
|
btnNetzwerk.addActionListener(new ActionListener() {
|
|||
|
public void actionPerformed(ActionEvent arg0) {
|
|||
|
BeaconSender sender = NetworkSelectorDialog.show(PulsCounter.getBeacon());
|
|||
|
if (sender != null){
|
|||
|
|
|||
|
int port = Integer.decode(sender.getProperties().getProperty("rpc.simple.port"));
|
|||
|
|
|||
|
SimpleRPCService service = new SimpleRPCService(sender.getInetAddress(), port);
|
|||
|
IPulsCounter ipc = service.createProxy(IPulsCounter.class);
|
|||
|
|
|||
|
counterChannels.clear();
|
|||
|
|
|||
|
changeDeviceConnection(ipc);
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
GridBagConstraints gbc_btnNetzwerk = new GridBagConstraints();
|
|||
|
gbc_btnNetzwerk.insets = new Insets(0, 0, 5, 5);
|
|||
|
gbc_btnNetzwerk.gridx = 0;
|
|||
|
gbc_btnNetzwerk.gridy = 0;
|
|||
|
panel_1.add(btnNetzwerk, gbc_btnNetzwerk);
|
|||
|
|
|||
|
JButton btnLokal = new JButton("Lokal");
|
|||
|
btnLokal.addActionListener(new ActionListener() {
|
|||
|
public void actionPerformed(ActionEvent e) {
|
|||
|
try {
|
|||
|
SimpleRPCService service;
|
|||
|
service = new SimpleRPCService(InetAddress.getLocalHost(), 44352);
|
|||
|
IPulsCounter ipc = service.createProxy(IPulsCounter.class);
|
|||
|
|
|||
|
counterChannels.clear();
|
|||
|
|
|||
|
changeDeviceConnection(ipc);
|
|||
|
} catch (UnknownHostException e1) {
|
|||
|
// TODO Auto-generated catch block
|
|||
|
e1.printStackTrace();
|
|||
|
}
|
|||
|
}
|
|||
|
});
|
|||
|
GridBagConstraints gbc_btnLokal = new GridBagConstraints();
|
|||
|
gbc_btnLokal.insets = new Insets(0, 0, 5, 0);
|
|||
|
gbc_btnLokal.gridx = 2;
|
|||
|
gbc_btnLokal.gridy = 0;
|
|||
|
panel_1.add(btnLokal, gbc_btnLokal);
|
|||
|
|
|||
|
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 = 1;
|
|||
|
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 = 1;
|
|||
|
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 = 1;
|
|||
|
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};
|
|||
|
gbl_panel_3.rowHeights = new int[]{0, 0};
|
|||
|
gbl_panel_3.columnWeights = new double[]{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.gridx = 3;
|
|||
|
gbc_btnAlle.gridy = 0;
|
|||
|
panel_3.add(btnAlle, gbc_btnAlle);
|
|||
|
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};
|
|||
|
gbl_panel_4.rowHeights = new int[]{0, 0};
|
|||
|
gbl_panel_4.columnWeights = new double[]{1.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);
|
|||
|
|
|||
|
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 = 1;
|
|||
|
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 = 2;
|
|||
|
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() {
|
|||
|
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)
|
|||
|
{
|
|||
|
PulsCounter.getDeviceConnection().setChannelCounter(cc.getChannel(), 0);
|
|||
|
|
|||
|
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();
|
|||
|
}
|
|||
|
|
|||
|
private void updateCounter()
|
|||
|
{
|
|||
|
lActivity.setText("Werte aktualisieren...");
|
|||
|
System.err.println("Werte aktualisieren...");
|
|||
|
|
|||
|
if (counterChannels == null)
|
|||
|
{
|
|||
|
tmCounter.setRows(counterChannels);
|
|||
|
}
|
|||
|
|
|||
|
IPulsCounter ipc = PulsCounter.getDeviceConnection();
|
|||
|
|
|||
|
if (ipc == null)
|
|||
|
return;
|
|||
|
|
|||
|
int nch = ipc.getChannels();
|
|||
|
|
|||
|
System.err.println(String.format("GUI: updateCounter(): Channel Array Size: %d / %d",nch,counterChannels.size()));
|
|||
|
|
|||
|
|
|||
|
if (nch != counterChannels.size()){
|
|||
|
counterChannels.clear();
|
|||
|
|
|||
|
for (int i=0;i<nch;i++){
|
|||
|
counterChannels.add(new CounterChannel(i));
|
|||
|
}
|
|||
|
|
|||
|
loadChannelNames();
|
|||
|
loadChannelOffsets();
|
|||
|
|
|||
|
tmCounter.setRows(counterChannels);
|
|||
|
}
|
|||
|
|
|||
|
int[] counters = ipc.getChannelCounters();
|
|||
|
|
|||
|
for (CounterChannel channel: counterChannels){
|
|||
|
channel.setValue(counters[channel.getChannel()]);
|
|||
|
}
|
|||
|
|
|||
|
lActivity.setText("warten...");
|
|||
|
tCounter.repaint();
|
|||
|
}
|
|||
|
|
|||
|
private void saveCorrection(int row)
|
|||
|
{
|
|||
|
System.err.println(String.format("Korrekturwert f<>r Kanal %d = %d",row + 1,tmCounter.getRow(row,CounterChannel.class).getCorrect()));
|
|||
|
PulsCounter.getDeviceConnection().setChannelOffset(row, tmCounter.getRow(row,CounterChannel.class).getCorrect());
|
|||
|
}
|
|||
|
|
|||
|
private void saveChannelName(int channel)
|
|||
|
{
|
|||
|
PulsCounter.getDeviceConnection().setChannelName(channel, counterChannels.get(channel).getBezeichnung());
|
|||
|
}
|
|||
|
private void loadChannelNames()
|
|||
|
{
|
|||
|
for (CounterChannel channel: counterChannels){
|
|||
|
channel.setBezeichnung(PulsCounter.getDeviceConnection().getChannelName(channel.getChannel()));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void loadChannelOffsets() {
|
|||
|
|
|||
|
int[] offsets = PulsCounter.getDeviceConnection().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()]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void resetAllChannels() {
|
|||
|
for (CounterChannel channel: counterChannels){
|
|||
|
PulsCounter.getDeviceConnection().setChannelCounter(channel.getChannel(), 0);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void changeDeviceConnection(IPulsCounter ipc){
|
|||
|
PulsCounter.setDeviceConnection(ipc);
|
|||
|
|
|||
|
tfPhysicalInterface.setText(ipc.getPhysicalInterfaceName());
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
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(){
|
|||
|
String pn = (String)JObjectSelector.execute(PulsCounter.getDeviceConnection().getPhysicalInterfaceNames());
|
|||
|
PulsCounter.getDeviceConnection().setPhysicalInterfaceName(pn);
|
|||
|
tfPhysicalInterface.setText(pn);
|
|||
|
}
|
|||
|
|
|||
|
}
|