01: package vicazh.hyperpool.stream.net;
02:
03: import javax.swing.*;
04: import javax.swing.event.*;
05: import vicazh.hyperpool.*;
06: import vicazh.hyperpool.Start;
07: import java.awt.event.*;
08: import java.util.logging.*;
09:
10: /**
11: * The graphic out service
12: *
13: * @author Victor Zhigunov
14: * @version 0.4.0
15: */
16: public class IOutService extends IService implements OutServiceMBean,
17: ActionListener, DocumentListener {
18: private JTextField textHost;
19:
20: private JFormattedTextField textPort;
21:
22: private JButton buttonOK;
23:
24: /**
25: * @param name
26: * service name
27: * @param textHost
28: * host text field
29: * @param textPort
30: * port text field
31: * @param buttonOK
32: * OK button
33: */
34: public IOutService(String name, JTextField textHost,
35: JFormattedTextField textPort, JButton buttonOK) {
36: super (OutServiceMBean.class, name);
37: textHost.getDocument().addDocumentListener(this );
38: this .textHost = textHost;
39: textPort.getDocument().addDocumentListener(this );
40: this .textPort = textPort;
41: buttonOK.setEnabled(false);
42: buttonOK.addActionListener(this );
43: this .buttonOK = buttonOK;
44: }
45:
46: public void actionPerformed(ActionEvent e) {
47: buttonOK.setEnabled(false);
48: OutService s = new OutService();
49: s.setHost(textHost.getText());
50: s.setPort((Integer) textPort.getValue());
51: try {
52: setAttribute(OutServiceMBean.OPTIONS, s);
53: } catch (Exception ex) {
54: Start.logger.log(Level.SEVERE, ex.getMessage(), ex);
55: }
56: }
57:
58: public void insertUpdate(DocumentEvent e) {
59: update();
60: }
61:
62: public void removeUpdate(DocumentEvent e) {
63: update();
64: }
65:
66: public void changedUpdate(DocumentEvent e) {
67: update();
68: }
69:
70: private void update() {
71: buttonOK.setEnabled(true);
72: }
73:
74: protected void otherNotification(String type, Object value) {
75: textHost.setText(((OutService) value).getHost());
76: textPort.setValue(((OutService) value).getPort());
77: }
78: }
|