java-org.hwo.servicelink/src/org/hwo/ui/servicelink/register/ServiceRegisterEditorDialog...

261 lines
7.9 KiB
Java

package org.hwo.ui.servicelink.register;
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.interactiveobjects.IInteractiveObjectEditor;
import org.hwo.ui.KeyStrokeHelper;
import org.hwo.ui.KeyStrokeListener;
import org.hwo.ui.KeyStrokeParameters;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.BoxLayout;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.JScrollPane;
public class ServiceRegisterEditorDialog extends JDialog implements IInteractiveObjectEditor{
private final JPanel contentPanel = new JPanel();
private ServiceRegister serviceRegister;
private JTextField tfAx;
private JTextField tfNode;
private JTextField tfRegister;
private JPanel panelEditorControl;
private JTextField tfRegname;
private KeyStrokeHelper keyStrokeHelper;
private JScrollPane scrollPane;
/**
* Create the dialog.
*/
public ServiceRegisterEditorDialog() {
addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
if (serviceRegister != null)
serviceRegister.getEditorComponent().requestFocusInWindow();
}
});
setBounds(100, 100, 327, 318);
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};
gbl_contentPanel.rowHeights = new int[]{0, 0, 0};
gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE};
gbl_contentPanel.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
contentPanel.setLayout(gbl_contentPanel);
{
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "Service Register", TitledBorder.LEADING, TitledBorder.TOP, 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;
contentPanel.add(panel, gbc_panel);
GridBagLayout gbl_panel = new GridBagLayout();
gbl_panel.columnWidths = new int[]{0, 0, 0};
gbl_panel.rowHeights = new int[]{0, 0, 0, 0, 0};
gbl_panel.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
panel.setLayout(gbl_panel);
{
JLabel lblAchse = new JLabel("Achse:");
GridBagConstraints gbc_lblAchse = new GridBagConstraints();
gbc_lblAchse.insets = new Insets(0, 0, 5, 5);
gbc_lblAchse.anchor = GridBagConstraints.EAST;
gbc_lblAchse.gridx = 0;
gbc_lblAchse.gridy = 0;
panel.add(lblAchse, gbc_lblAchse);
}
{
tfAx = new JTextField();
tfAx.setEditable(false);
GridBagConstraints gbc_tfAx = new GridBagConstraints();
gbc_tfAx.insets = new Insets(0, 0, 5, 0);
gbc_tfAx.fill = GridBagConstraints.HORIZONTAL;
gbc_tfAx.gridx = 1;
gbc_tfAx.gridy = 0;
panel.add(tfAx, gbc_tfAx);
tfAx.setColumns(10);
}
{
JLabel lblKnoten = new JLabel("Knoten:");
GridBagConstraints gbc_lblKnoten = new GridBagConstraints();
gbc_lblKnoten.anchor = GridBagConstraints.EAST;
gbc_lblKnoten.insets = new Insets(0, 0, 5, 5);
gbc_lblKnoten.gridx = 0;
gbc_lblKnoten.gridy = 1;
panel.add(lblKnoten, gbc_lblKnoten);
}
{
tfNode = new JTextField();
tfNode.setEditable(false);
GridBagConstraints gbc_tfNode = new GridBagConstraints();
gbc_tfNode.insets = new Insets(0, 0, 5, 0);
gbc_tfNode.fill = GridBagConstraints.HORIZONTAL;
gbc_tfNode.gridx = 1;
gbc_tfNode.gridy = 1;
panel.add(tfNode, gbc_tfNode);
tfNode.setColumns(10);
}
{
JLabel lblRegister = new JLabel("Register:");
GridBagConstraints gbc_lblRegister = new GridBagConstraints();
gbc_lblRegister.anchor = GridBagConstraints.EAST;
gbc_lblRegister.insets = new Insets(0, 0, 5, 5);
gbc_lblRegister.gridx = 0;
gbc_lblRegister.gridy = 2;
panel.add(lblRegister, gbc_lblRegister);
}
{
tfRegister = new JTextField();
tfRegister.setEditable(false);
GridBagConstraints gbc_tfRegister = new GridBagConstraints();
gbc_tfRegister.insets = new Insets(0, 0, 5, 0);
gbc_tfRegister.fill = GridBagConstraints.HORIZONTAL;
gbc_tfRegister.gridx = 1;
gbc_tfRegister.gridy = 2;
panel.add(tfRegister, gbc_tfRegister);
tfRegister.setColumns(10);
}
{
JLabel lblNewLabel = new JLabel("Bezeichnung:");
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
gbc_lblNewLabel.anchor = GridBagConstraints.EAST;
gbc_lblNewLabel.insets = new Insets(0, 0, 0, 5);
gbc_lblNewLabel.gridx = 0;
gbc_lblNewLabel.gridy = 3;
panel.add(lblNewLabel, gbc_lblNewLabel);
}
{
tfRegname = new JTextField();
tfRegname.setEditable(false);
GridBagConstraints gbc_tfRegname = new GridBagConstraints();
gbc_tfRegname.fill = GridBagConstraints.HORIZONTAL;
gbc_tfRegname.gridx = 1;
gbc_tfRegname.gridy = 3;
panel.add(tfRegname, gbc_tfRegname);
tfRegname.setColumns(10);
}
}
{
panelEditorControl = new JPanel();
GridBagConstraints gbc_panelEditorControl = new GridBagConstraints();
gbc_panelEditorControl.fill = GridBagConstraints.BOTH;
gbc_panelEditorControl.gridx = 0;
gbc_panelEditorControl.gridy = 1;
contentPanel.add(panelEditorControl, gbc_panelEditorControl);
panelEditorControl.setLayout(new BoxLayout(panelEditorControl, BoxLayout.X_AXIS));
{
scrollPane = new JScrollPane();
panelEditorControl.add(scrollPane);
}
}
{
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 arg0) {
accept();
}
});
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cancel();
}
});
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
initialize();
}
private void initialize()
{
keyStrokeHelper = new KeyStrokeHelper(this.getRootPane());
keyStrokeHelper.setFocusedWindow(true);
keyStrokeHelper.registerKeyStrokeListener(new KeyStrokeListener() {
@Override
public void keyStroke(KeyStrokeParameters parameters) {
switch (parameters.getKeyCode())
{
case KeyEvent.VK_ESCAPE:
cancel();
break;
}
}
});
keyStrokeHelper.addKeyCode(KeyEvent.VK_ESCAPE);
}
private void accept()
{
serviceRegister.acceptEditorValue();
setVisible(false);
}
private void cancel()
{
setVisible(false);
}
private void initializeView()
{
scrollPane.setViewportView(null);
if (serviceRegister != null)
{
tfAx.setText(serviceRegister.getAx().toString());
tfNode.setText(serviceRegister.getNode().toString());
tfRegister.setText(serviceRegister.getRegister().toString());
tfRegname.setText(serviceRegister.getRegisterName());
scrollPane.setViewportView(serviceRegister.getEditorComponent());
serviceRegister.updateEditorValue();
};
doLayout();
}
@Override
public void setInteractiveObject(Object o) {
serviceRegister = (ServiceRegister)o;
initializeView();
}
@Override
public Object getInteractiveObject() {
return serviceRegister;
}
}