package org.hwo.pulscounter.ui; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import java.awt.Dialog.ModalExclusionType; import javax.swing.JTabbedPane; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import javax.swing.JLabel; import java.awt.Insets; import javax.swing.JTextField; import javax.swing.JButton; import org.hwo.io.SerialPort; import org.hwo.io.SerialPortChooser; import org.hwo.pulscounter.PulsCounter2Application; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class AppSettingsFrame extends JFrame { private JPanel contentPane; private JTextField tfInterface; private SerialPort selectedSerialPort; /** * Create the frame. */ public AppSettingsFrame() { setTitle("Einstellungen"); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBounds(100, 100, 603, 447); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); contentPane.add(tabbedPane, BorderLayout.CENTER); JPanel panel = new JPanel(); tabbedPane.addTab("Kommunikation", null, panel, null); tabbedPane.setEnabledAt(0, true); GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[]{0, 0, 0, 0}; gbl_panel.rowHeights = new int[]{0, 0, 0, 0}; gbl_panel.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE}; gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE}; panel.setLayout(gbl_panel); JLabel lblSchnittstelle = new JLabel("Schnittstelle:"); GridBagConstraints gbc_lblSchnittstelle = new GridBagConstraints(); gbc_lblSchnittstelle.anchor = GridBagConstraints.EAST; gbc_lblSchnittstelle.insets = new Insets(0, 0, 5, 5); gbc_lblSchnittstelle.gridx = 0; gbc_lblSchnittstelle.gridy = 0; panel.add(lblSchnittstelle, gbc_lblSchnittstelle); tfInterface = new JTextField(); GridBagConstraints gbc_tfInterface = new GridBagConstraints(); gbc_tfInterface.anchor = GridBagConstraints.NORTH; gbc_tfInterface.insets = new Insets(0, 0, 5, 5); gbc_tfInterface.fill = GridBagConstraints.HORIZONTAL; gbc_tfInterface.gridx = 1; gbc_tfInterface.gridy = 0; panel.add(tfInterface, gbc_tfInterface); tfInterface.setColumns(10); JButton btnWhlen = new JButton("wählen..."); btnWhlen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { chooseSerialPort(); } }); GridBagConstraints gbc_btnWhlen = new GridBagConstraints(); gbc_btnWhlen.insets = new Insets(0, 0, 5, 0); gbc_btnWhlen.gridx = 2; gbc_btnWhlen.gridy = 0; panel.add(btnWhlen, gbc_btnWhlen); JPanel panel_1 = new JPanel(); contentPane.add(panel_1, BorderLayout.SOUTH); GridBagLayout gbl_panel_1 = new GridBagLayout(); gbl_panel_1.columnWidths = new int[]{0, 0, 0}; gbl_panel_1.rowHeights = new int[]{0, 0}; gbl_panel_1.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE}; gbl_panel_1.rowWeights = new double[]{0.0, Double.MIN_VALUE}; panel_1.setLayout(gbl_panel_1); JButton bCANCEL = new JButton("cancel"); bCANCEL.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); GridBagConstraints gbc_bCANCEL = new GridBagConstraints(); gbc_bCANCEL.fill = GridBagConstraints.HORIZONTAL; gbc_bCANCEL.insets = new Insets(0, 0, 0, 5); gbc_bCANCEL.gridx = 0; gbc_bCANCEL.gridy = 0; panel_1.add(bCANCEL, gbc_bCANCEL); JButton bOK = new JButton("OK"); bOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { accept(); setVisible(false); } }); GridBagConstraints gbc_bOK = new GridBagConstraints(); gbc_bOK.fill = GridBagConstraints.HORIZONTAL; gbc_bOK.gridx = 1; gbc_bOK.gridy = 0; panel_1.add(bOK, gbc_bOK); initialize(); } private void initialize(){ PulsCounter2Application pc2a = PulsCounter2Application.getApplication(); selectedSerialPort = pc2a.getSerialPort(); if (selectedSerialPort != null) tfInterface.setText(selectedSerialPort.getPortName()); } private void accept(){ PulsCounter2Application pc2a = PulsCounter2Application.getApplication(); pc2a.setSerialPort(selectedSerialPort); } private void chooseSerialPort(){ PulsCounter2Application pc2a = PulsCounter2Application.getApplication(); SerialPortChooser spc = new SerialPortChooser(); String selectedPortName = null; if (selectedSerialPort != null) selectedPortName = selectedSerialPort.getPortName(); SerialPort sp = spc.execute(selectedPortName); if (sp != null){ selectedSerialPort = sp; tfInterface.setText(sp.getPortName()); }; } }