Neu: NewSerialPortSetup

thobaben_diagram
Harald Wolff 2015-08-12 22:28:22 +02:00
parent dc815b97e6
commit e1d027e285
1 changed files with 212 additions and 0 deletions

View File

@ -0,0 +1,212 @@
package org.hwo.ui.dialog;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import org.hwo.io.NewSerialPort.NewSerialPort;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Window.Type;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import org.hwo.io.NewSerialPort.Parity;
import org.hwo.io.NewSerialPort.HandShake;
import org.hwo.io.NewSerialPort.BaudRate;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Dialog.ModalExclusionType;
public class NewSerialPortSetup extends JDialog {
private final JPanel contentPanel = new JPanel();
private NewSerialPort newSerialPort;
private JComboBox cbHandShake;
private JComboBox cbParity;
private JComboBox cbStopBits;
private JComboBox cbDataBits;
private JComboBox cbSpeed;
/**
* Create the dialog.
*/
public NewSerialPortSetup() {
setTitle("Serielle Schnittstelle einrichten...");
setModal(true);
setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.NORTH);
GridBagLayout gbl_contentPanel = new GridBagLayout();
gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
gbl_contentPanel.rowHeights = new int[]{0, 0, 0, 0, 0, 0};
gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
gbl_contentPanel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
contentPanel.setLayout(gbl_contentPanel);
{
JLabel lblGeschwindigkeit = new JLabel("Geschwindigkeit:");
GridBagConstraints gbc_lblGeschwindigkeit = new GridBagConstraints();
gbc_lblGeschwindigkeit.anchor = GridBagConstraints.EAST;
gbc_lblGeschwindigkeit.insets = new Insets(0, 0, 5, 5);
gbc_lblGeschwindigkeit.gridx = 0;
gbc_lblGeschwindigkeit.gridy = 0;
contentPanel.add(lblGeschwindigkeit, gbc_lblGeschwindigkeit);
}
{
cbSpeed = new JComboBox();
cbSpeed.setModel(new DefaultComboBoxModel(BaudRate.values()));
GridBagConstraints gbc_cbSpeed = new GridBagConstraints();
gbc_cbSpeed.insets = new Insets(0, 0, 5, 0);
gbc_cbSpeed.fill = GridBagConstraints.HORIZONTAL;
gbc_cbSpeed.gridx = 1;
gbc_cbSpeed.gridy = 0;
contentPanel.add(cbSpeed, gbc_cbSpeed);
}
{
JLabel lblDatenbits = new JLabel("Datenbits:");
GridBagConstraints gbc_lblDatenbits = new GridBagConstraints();
gbc_lblDatenbits.insets = new Insets(0, 0, 5, 5);
gbc_lblDatenbits.gridx = 0;
gbc_lblDatenbits.gridy = 1;
contentPanel.add(lblDatenbits, gbc_lblDatenbits);
}
{
cbDataBits = new JComboBox();
cbDataBits.setModel(new DefaultComboBoxModel(new String[] {"5", "6", "7", "8"}));
GridBagConstraints gbc_cbDataBits = new GridBagConstraints();
gbc_cbDataBits.insets = new Insets(0, 0, 5, 0);
gbc_cbDataBits.fill = GridBagConstraints.HORIZONTAL;
gbc_cbDataBits.gridx = 1;
gbc_cbDataBits.gridy = 1;
contentPanel.add(cbDataBits, gbc_cbDataBits);
}
{
JLabel lblStopbis = new JLabel("StopBis:");
GridBagConstraints gbc_lblStopbis = new GridBagConstraints();
gbc_lblStopbis.anchor = GridBagConstraints.EAST;
gbc_lblStopbis.insets = new Insets(0, 0, 5, 5);
gbc_lblStopbis.gridx = 0;
gbc_lblStopbis.gridy = 2;
contentPanel.add(lblStopbis, gbc_lblStopbis);
}
{
cbStopBits = new JComboBox();
cbStopBits.setModel(new DefaultComboBoxModel(new String[] {"1", "2"}));
GridBagConstraints gbc_cbStopBits = new GridBagConstraints();
gbc_cbStopBits.insets = new Insets(0, 0, 5, 0);
gbc_cbStopBits.fill = GridBagConstraints.HORIZONTAL;
gbc_cbStopBits.gridx = 1;
gbc_cbStopBits.gridy = 2;
contentPanel.add(cbStopBits, gbc_cbStopBits);
}
{
JLabel lblParitt = new JLabel("Parität:");
GridBagConstraints gbc_lblParitt = new GridBagConstraints();
gbc_lblParitt.anchor = GridBagConstraints.EAST;
gbc_lblParitt.insets = new Insets(0, 0, 5, 5);
gbc_lblParitt.gridx = 0;
gbc_lblParitt.gridy = 3;
contentPanel.add(lblParitt, gbc_lblParitt);
}
{
cbParity = new JComboBox();
cbParity.setModel(new DefaultComboBoxModel(Parity.values()));
GridBagConstraints gbc_cbParity = new GridBagConstraints();
gbc_cbParity.insets = new Insets(0, 0, 5, 0);
gbc_cbParity.fill = GridBagConstraints.HORIZONTAL;
gbc_cbParity.gridx = 1;
gbc_cbParity.gridy = 3;
contentPanel.add(cbParity, gbc_cbParity);
}
{
JLabel lblHandshake = new JLabel("Handshake:");
GridBagConstraints gbc_lblHandshake = new GridBagConstraints();
gbc_lblHandshake.insets = new Insets(0, 0, 0, 5);
gbc_lblHandshake.gridx = 0;
gbc_lblHandshake.gridy = 4;
contentPanel.add(lblHandshake, gbc_lblHandshake);
}
{
cbHandShake = new JComboBox();
cbHandShake.setModel(new DefaultComboBoxModel(HandShake.values()));
GridBagConstraints gbc_cbHandShake = new GridBagConstraints();
gbc_cbHandShake.fill = GridBagConstraints.HORIZONTAL;
gbc_cbHandShake.gridx = 1;
gbc_cbHandShake.gridy = 4;
contentPanel.add(cbHandShake, gbc_cbHandShake);
}
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
applySettings();
setVisible(false);
}
});
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
});
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
loadSettings();
}
public NewSerialPort getNewSerialPort() {
return newSerialPort;
}
public void setNewSerialPort(NewSerialPort newSerialPort) {
this.newSerialPort = newSerialPort;
loadSettings();
}
private void applySettings(){
if (this.newSerialPort!=null){
newSerialPort.setBaudRate((BaudRate)cbSpeed.getSelectedItem());
newSerialPort.setParity((Parity)cbParity.getSelectedItem());
newSerialPort.setHandShake((HandShake)cbHandShake.getSelectedItem());
newSerialPort.setDatabits(Integer.parseInt(cbDataBits.getSelectedItem().toString()));
newSerialPort.setStopBit2(cbStopBits.getSelectedIndex()==1);
}
}
private void loadSettings(){
if (newSerialPort == null){
newSerialPort = new NewSerialPort("");
}
cbSpeed.setSelectedItem(newSerialPort.getBaudRate2());
cbParity.setSelectedItem(newSerialPort.getParity());
cbHandShake.setSelectedItem(newSerialPort.getHandShake());
if (newSerialPort.getStopBit2())
cbStopBits.setSelectedIndex(1);
else
cbStopBits.setSelectedIndex(0);
cbDataBits.setSelectedItem(new Integer(newSerialPort.getDatabits()).toString());
}
}