package org.hwo.pulscounter.ui; 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 org.hwo.i18n.Messages; import org.hwo.pulscounter.simplescript.SimpleScript; import org.hwo.pulscounter.simplescript.SimpleScript.ScriptCondition; import org.hwo.pulscounter.simplescript.SimpleScript.ScriptOperation; import org.hwo.pulscounter.simplescript.SimpleScript.SimpleScriptElement; import org.hwo.ui.JComboBoxEx; import java.awt.Dialog.ModalExclusionType; import java.awt.Dialog.ModalityType; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.border.TitledBorder; import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JComboBox; import java.awt.Font; public class SimpleScriptElementEditor extends JDialog { public static boolean show(Component parent,SimpleScriptElement simpleScriptElement){ SimpleScriptElementEditor editor = new SimpleScriptElementEditor(); if (parent != null){ editor.setLocationRelativeTo(parent); } editor.setSimpleScriptElement(simpleScriptElement); editor.setVisible(true); return editor.isAccepted(); } private SimpleScriptElement simpleScriptElement; private boolean accepted; private final JPanel contentPanel = new JPanel(); private SimpleScriptAddressEditor ssaA; private SimpleScriptAddressEditor ssaB; private SimpleScriptAddressEditor ssaZ; private JComboBoxEx cbCondition; private JComboBoxEx cbOperation; /** * Create the dialog. */ public SimpleScriptElementEditor() { setResizable(false); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setTitle(Messages.getString("Skriptelement bearbeiten")); setModalityType(ModalityType.APPLICATION_MODAL); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); setBounds(100, 100, 519, 350); 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, 0, 0, 0}; gbl_contentPanel.columnWeights = new double[]{1.0, 1.0, Double.MIN_VALUE}; gbl_contentPanel.rowWeights = new double[]{0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE}; contentPanel.setLayout(gbl_contentPanel); { JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), Messages.getString("Eingangswert A"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.insets = new Insets(0, 0, 5, 5); gbc_panel.fill = GridBagConstraints.BOTH; gbc_panel.gridx = 0; gbc_panel.gridy = 0; contentPanel.add(panel, gbc_panel); GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[]{0, 0}; gbl_panel.rowHeights = new int[]{0, 0}; gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; panel.setLayout(gbl_panel); { ssaA = new SimpleScriptAddressEditor(); GridBagConstraints gbc_ssaA = new GridBagConstraints(); gbc_ssaA.fill = GridBagConstraints.BOTH; gbc_ssaA.gridx = 0; gbc_ssaA.gridy = 0; panel.add(ssaA, gbc_ssaA); } } { JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), Messages.getString("Eingangswert B"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.insets = new Insets(0, 0, 5, 0); gbc_panel.fill = GridBagConstraints.BOTH; gbc_panel.gridx = 1; gbc_panel.gridy = 0; contentPanel.add(panel, gbc_panel); GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[]{0, 0}; gbl_panel.rowHeights = new int[]{0, 0}; gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; panel.setLayout(gbl_panel); { ssaB = new SimpleScriptAddressEditor(); GridBagConstraints gbc_ssaB = new GridBagConstraints(); gbc_ssaB.fill = GridBagConstraints.BOTH; gbc_ssaB.gridx = 0; gbc_ssaB.gridy = 0; panel.add(ssaB, gbc_ssaB); } } { JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)),Messages.getString("Bedingung"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.insets = new Insets(0, 0, 5, 0); gbc_panel.gridwidth = 2; gbc_panel.fill = GridBagConstraints.BOTH; gbc_panel.gridx = 0; gbc_panel.gridy = 1; contentPanel.add(panel, gbc_panel); GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[]{0, 0}; gbl_panel.rowHeights = new int[]{0, 0}; gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE}; panel.setLayout(gbl_panel); { cbCondition = new JComboBoxEx(); cbCondition.setFont(new Font("Courier", Font.BOLD, 14)); GridBagConstraints gbc_cbCondition = new GridBagConstraints(); gbc_cbCondition.fill = GridBagConstraints.HORIZONTAL; gbc_cbCondition.gridx = 0; gbc_cbCondition.gridy = 0; cbCondition.setItems(SimpleScript.ScriptCondition.values()); panel.add(cbCondition, gbc_cbCondition); } } { JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)),Messages.getString("Operation"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.insets = new Insets(0, 0, 5, 0); gbc_panel.gridwidth = 2; gbc_panel.fill = GridBagConstraints.BOTH; gbc_panel.gridx = 0; gbc_panel.gridy = 2; contentPanel.add(panel, gbc_panel); GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[]{0, 0}; gbl_panel.rowHeights = new int[]{0, 0}; gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gbl_panel.rowWeights = new double[]{0.0, Double.MIN_VALUE}; panel.setLayout(gbl_panel); { cbOperation = new JComboBoxEx(); cbOperation.setFont(new Font("Courier", Font.BOLD, 14)); GridBagConstraints gbc_cbOperation = new GridBagConstraints(); gbc_cbOperation.fill = GridBagConstraints.HORIZONTAL; gbc_cbOperation.gridx = 0; gbc_cbOperation.gridy = 0; cbOperation.setItems(SimpleScript.ScriptOperation.values()); panel.add(cbOperation, gbc_cbOperation); } } { JPanel panel = new JPanel(); panel.setBorder(new TitledBorder(new LineBorder(new Color(184, 207, 229)), Messages.getString("Ausgangswert Z"), TitledBorder.LEADING, TitledBorder.TOP, null, new Color(51, 51, 51))); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.insets = new Insets(0, 0, 0, 5); gbc_panel.fill = GridBagConstraints.BOTH; gbc_panel.gridx = 0; gbc_panel.gridy = 3; contentPanel.add(panel, gbc_panel); GridBagLayout gbl_panel = new GridBagLayout(); gbl_panel.columnWidths = new int[]{0, 0}; gbl_panel.rowHeights = new int[]{0, 0}; gbl_panel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gbl_panel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; panel.setLayout(gbl_panel); { ssaZ = new SimpleScriptAddressEditor(); GridBagConstraints gbc_ssaZ = new GridBagConstraints(); gbc_ssaZ.fill = GridBagConstraints.BOTH; gbc_ssaZ.gridx = 0; gbc_ssaZ.gridy = 0; panel.add(ssaZ, gbc_ssaZ); } } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton okButton = new JButton(Messages.getString("OK")); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { accept(); } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton(Messages.getString("Cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancel(); } }); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } } public SimpleScriptElement getSimpleScriptElement() { return simpleScriptElement; } public void setSimpleScriptElement(SimpleScriptElement simpleScriptElement) { this.simpleScriptElement = simpleScriptElement; ssaA.setAddress( simpleScriptElement.getA() ); ssaB.setAddress( simpleScriptElement.getB() ); ssaZ.setAddress( simpleScriptElement.getZ() ); cbCondition.setSelectedItem(simpleScriptElement.getScriptCondition()); cbOperation.setSelectedItem(simpleScriptElement.getScriptOperation()); } private void accept(){ simpleScriptElement.setA(ssaA.getAddress()); simpleScriptElement.setB(ssaB.getAddress()); simpleScriptElement.setZ(ssaZ.getAddress()); simpleScriptElement.setScriptOperation((ScriptOperation)cbOperation.getSelectedItem()); simpleScriptElement.setScriptCondition((ScriptCondition)cbCondition.getSelectedItem()); accepted = true; setVisible(false); } private void cancel(){ setVisible(false); } public boolean isAccepted() { return accepted; } }