287 lines
9.4 KiB
Java
287 lines
9.4 KiB
Java
package org.hwo.pulscounter.ui;
|
|
|
|
import static org.hwo.logging.LogLevel.*;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.EventQueue;
|
|
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.border.EmptyBorder;
|
|
import javax.swing.event.ListSelectionEvent;
|
|
import javax.swing.event.ListSelectionListener;
|
|
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.Insets;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Date;
|
|
|
|
import javax.swing.border.BevelBorder;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JDialog;
|
|
|
|
import java.awt.FlowLayout;
|
|
|
|
import org.hwo.i18n.Messages;
|
|
import org.hwo.models.TableMapper.TableMapper;
|
|
import org.hwo.models.TableMapper.TableMapperListener;
|
|
import org.hwo.pulscounter.PulsCounterApplication;
|
|
import org.hwo.pulscounter.device.IDeviceConnector;
|
|
import org.hwo.pulscounter.simplescript.SimpleScript;
|
|
import org.hwo.ui.JMappedTable;
|
|
import org.hwo.ui.JObjectSelector;
|
|
|
|
import javax.swing.JScrollPane;
|
|
import java.awt.event.ActionListener;
|
|
import java.text.DateFormat;
|
|
import java.awt.event.ActionEvent;
|
|
import static org.hwo.logging.Logging.*;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.EventQueue;
|
|
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.border.EmptyBorder;
|
|
import javax.swing.event.ListSelectionEvent;
|
|
import javax.swing.event.ListSelectionListener;
|
|
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.Insets;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
|
|
import javax.swing.border.BevelBorder;
|
|
import javax.swing.JButton;
|
|
import java.awt.FlowLayout;
|
|
|
|
import org.hwo.models.TableMapper.TableMapper;
|
|
import org.hwo.models.TableMapper.TableMapperListener;
|
|
import org.hwo.pulscounter.PulsCounterApplication;
|
|
import org.hwo.pulscounter.simplescript.SimpleScript;
|
|
import org.hwo.ui.JMappedTable;
|
|
import javax.swing.JScrollPane;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.Dialog.ModalExclusionType;
|
|
import java.awt.Dialog.ModalityType;
|
|
import javax.swing.JTable;
|
|
|
|
public class SimpleScriptSetup extends JDialog {
|
|
|
|
private JPanel contentPane;
|
|
private JMappedTable scriptTable;
|
|
|
|
private ArrayList<SimpleScript> simpleScripts;
|
|
private JButton btnEntfernen;
|
|
private JButton btnBearbeiten;
|
|
private JButton btnNeu;
|
|
private JButton btnTransmit;
|
|
private JButton btnReceive;
|
|
|
|
public SimpleScriptSetup() {
|
|
setTitle(Messages.getString("Formeln"));
|
|
setModalityType(ModalityType.APPLICATION_MODAL);
|
|
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
setBounds(100, 100, 831, 406);
|
|
contentPane = new JPanel();
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
setContentPane(contentPane);
|
|
GridBagLayout gbl_contentPane = new GridBagLayout();
|
|
gbl_contentPane.columnWidths = new int[]{0, 0};
|
|
gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0};
|
|
gbl_contentPane.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
gbl_contentPane.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
|
|
contentPane.setLayout(gbl_contentPane);
|
|
|
|
JPanel panel = new JPanel();
|
|
FlowLayout flowLayout = (FlowLayout) panel.getLayout();
|
|
flowLayout.setAlignment(FlowLayout.LEFT);
|
|
panel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
|
|
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;
|
|
contentPane.add(panel, gbc_panel);
|
|
|
|
btnNeu = new JButton(Messages.getString("neu..."));
|
|
btnNeu.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
scriptTable.getTableMapper().addRow(new SimpleScript());
|
|
}
|
|
});
|
|
panel.add(btnNeu);
|
|
|
|
btnBearbeiten = new JButton(Messages.getString("bearbeiten..."));
|
|
btnBearbeiten.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
scriptTable.getTableMapper().openEditor();
|
|
}
|
|
});
|
|
btnBearbeiten.setEnabled(false);
|
|
panel.add(btnBearbeiten);
|
|
|
|
btnEntfernen = new JButton(Messages.getString("entfernen"));
|
|
btnEntfernen.setEnabled(false);
|
|
btnEntfernen.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
SimpleScript sscript = scriptTable.getTableMapper().getSelectedRow(SimpleScript.class);
|
|
PulsCounterApplication.getApplication().getDatabase().removeSimpleScript( sscript.getId() );
|
|
scriptTable.getTableMapper().removeRow(sscript);
|
|
}
|
|
});
|
|
panel.add(btnEntfernen);
|
|
|
|
btnTransmit = new JButton(Messages.getString("auf Zähler übertragen...."));
|
|
btnTransmit.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
transmit();
|
|
}
|
|
});
|
|
btnTransmit.setEnabled(false);
|
|
panel.add(btnTransmit);
|
|
|
|
btnReceive = new JButton(Messages.getString("von Zähler holen...."));
|
|
btnReceive.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
receive();
|
|
}
|
|
});
|
|
panel.add(btnReceive);
|
|
|
|
JScrollPane scrollPane = new JScrollPane();
|
|
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
|
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
|
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
|
|
gbc_scrollPane.gridx = 0;
|
|
gbc_scrollPane.gridy = 1;
|
|
contentPane.add(scrollPane, gbc_scrollPane);
|
|
|
|
scriptTable = new JMappedTable(SimpleScript.class);
|
|
scriptTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
|
|
scriptTable.setFillsViewportHeight(true);
|
|
scrollPane.setViewportView(scriptTable);
|
|
|
|
JPanel panel_1 = new JPanel();
|
|
FlowLayout flowLayout_1 = (FlowLayout) panel_1.getLayout();
|
|
flowLayout_1.setAlignment(FlowLayout.RIGHT);
|
|
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
|
|
gbc_panel_1.fill = GridBagConstraints.BOTH;
|
|
gbc_panel_1.gridx = 0;
|
|
gbc_panel_1.gridy = 2;
|
|
contentPane.add(panel_1, gbc_panel_1);
|
|
|
|
JButton btnSchliessen = new JButton(Messages.getString("schliessen"));
|
|
btnSchliessen.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent e) {
|
|
setVisible(false);
|
|
}
|
|
});
|
|
panel_1.add(btnSchliessen);
|
|
|
|
initialize();
|
|
}
|
|
|
|
private void initialize(){
|
|
this.simpleScripts = new ArrayList<>();
|
|
|
|
this.simpleScripts.addAll(Arrays.asList(PulsCounterApplication.getApplication().getDatabase().getSimpleScripts()));
|
|
|
|
this.scriptTable.getTableMapper().setRows(simpleScripts);
|
|
this.scriptTable.getTableMapper().setReadOnly(true);
|
|
this.scriptTable.getTableMapper().setEditorEnabled(true);
|
|
this.scriptTable.getTableMapper().addListSelectionListener(new ListSelectionListener() {
|
|
|
|
@Override
|
|
public void valueChanged(ListSelectionEvent e) {
|
|
if (scriptTable.getTableMapper().getSelectedRow() == null){
|
|
btnBearbeiten.setEnabled(false);
|
|
btnEntfernen.setEnabled(false);
|
|
btnTransmit.setEnabled(false);
|
|
} else {
|
|
btnBearbeiten.setEnabled(true);
|
|
btnEntfernen.setEnabled(true);
|
|
btnTransmit.setEnabled(true);
|
|
}
|
|
}
|
|
});
|
|
this.scriptTable.getTableMapper().addTableMapperListener(new TableMapperListener() {
|
|
|
|
@Override
|
|
public boolean editorRequest(TableMapper tableMapper, Object row) {
|
|
if (row != null){
|
|
if (SimpleScriptEditor.show(SimpleScriptSetup.this,(SimpleScript)row)){
|
|
log(INFO,"store SimpleScript");
|
|
PulsCounterApplication.getApplication().getDatabase().storeSimpleScript((SimpleScript)row);
|
|
scriptTable.repaint();
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void ValueChanged(int row, int column) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void tableRowChanged(TableMapper sender, Object row) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void transmit(){
|
|
IDeviceConnector[] connectors = PulsCounterApplication.getApplication().getInterfaces().toArray(new IDeviceConnector[0]);
|
|
IDeviceConnector connector = JObjectSelector.execute(
|
|
connectors,
|
|
this,
|
|
Messages.getString("Schnittstelle wählen..."),
|
|
Messages.getString("Wählen Sie die Schnittstelle über die das Skript übertragen werden soll.")
|
|
);
|
|
|
|
if (connector != null){
|
|
log(INFO,"Übertrage Skript an Synololog an Schnittstelle %s", connector);
|
|
|
|
connector.setSimpleScript(((SimpleScript)scriptTable.getTableMapper().getSelectedRow()).getSimpleScriptElementsAsInt());
|
|
|
|
}
|
|
}
|
|
private void receive(){
|
|
IDeviceConnector[] connectors = PulsCounterApplication.getApplication().getInterfaces().toArray(new IDeviceConnector[0]);
|
|
IDeviceConnector connector = JObjectSelector.execute(
|
|
connectors,
|
|
this,
|
|
Messages.getString("Schnittstelle wählen..."),
|
|
Messages.getString("Wählen Sie die Schnittstelle über die das Skript empfangen werden soll.")
|
|
);
|
|
|
|
if (connector != null){
|
|
log(INFO,"Übertrage Skript von Synololog an Schnittstelle %s", connector);
|
|
|
|
int[] scriptElements = connector.getSimpleScript();
|
|
|
|
if (scriptElements == null){
|
|
JOptionPane.showMessageDialog(this, Messages.getString("Es konnte kein Skript vom gerät empfangen werden."));
|
|
} else {
|
|
SimpleScript simpleScript = new SimpleScript();
|
|
simpleScript.setSimpleScriptElements(scriptElements);
|
|
simpleScript.setName(String.format(Messages.getString("Von Gerät %s geholt am %s"), connector.getDeviceSerial(), DateFormat.getDateTimeInstance().format(new Date())));
|
|
|
|
scriptTable.getTableMapper().addRow(simpleScript);
|
|
PulsCounterApplication.getApplication().getDatabase().storeSimpleScript(simpleScript);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|