org.hwo.pulscounter/src/org/hwo/pulscounter/device/SimulatedCounterSettingsDia...

113 lines
3.3 KiB
Java

package org.hwo.pulscounter.device;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.JTextField;
import java.awt.Insets;
public class SimulatedCounterSettingsDialog extends JDialog {
public static boolean show(Component parent,SimulatedCounter counter){
SimulatedCounterSettingsDialog dlg = new SimulatedCounterSettingsDialog();
if (parent != null)
dlg.setLocationRelativeTo(parent);
dlg.setSerial(counter.getConnectionSettings());
dlg.setVisible(true);
if (dlg.accepted){
counter.setConnectionSettings(dlg.getSerial());
dlg.dispose();
return true;
}
return false;
}
private final JPanel contentPanel = new JPanel();
private boolean accepted;
private JTextField tfSerial;
public SimulatedCounterSettingsDialog() {
setTitle("Simulierter Zähler");
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setBounds(100, 100, 450, 300);
setModalityType(ModalityType.APPLICATION_MODAL);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
GridBagLayout gbl_contentPanel = new GridBagLayout();
gbl_contentPanel.columnWidths = new int[]{0, 0, 0};
gbl_contentPanel.rowHeights = new int[]{0, 0};
gbl_contentPanel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
gbl_contentPanel.rowWeights = new double[]{0.0, Double.MIN_VALUE};
contentPanel.setLayout(gbl_contentPanel);
{
JLabel lblAnschluss = new JLabel("Seriennummer:");
GridBagConstraints gbc_lblAnschluss = new GridBagConstraints();
gbc_lblAnschluss.insets = new Insets(0, 0, 0, 5);
gbc_lblAnschluss.anchor = GridBagConstraints.EAST;
gbc_lblAnschluss.gridx = 0;
gbc_lblAnschluss.gridy = 0;
contentPanel.add(lblAnschluss, gbc_lblAnschluss);
}
{
tfSerial = new JTextField();
GridBagConstraints gbc_tfSerial = new GridBagConstraints();
gbc_tfSerial.anchor = GridBagConstraints.NORTH;
gbc_tfSerial.fill = GridBagConstraints.HORIZONTAL;
gbc_tfSerial.gridx = 1;
gbc_tfSerial.gridy = 0;
contentPanel.add(tfSerial, gbc_tfSerial);
tfSerial.setColumns(10);
}
{
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) {
accepted = true;
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);
}
}
}
public String getSerial(){
return tfSerial.getText();
}
public void setSerial(String serial){
tfSerial.setText(serial);
}
}