01: package vicazh.hyperpool.stream.net.http.html;
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 message service
12: *
13: * @author Victor Zhigunov
14: * @version 0.4.0
15: */
16: public class IMessageService extends IService implements
17: MessageServiceMBean, ActionListener, DocumentListener {
18: private JTextField text;
19:
20: private DefaultComboBoxModel model;
21:
22: private JButton buttonOK;
23:
24: /**
25: * @param name
26: * service name
27: * @param text
28: * text field
29: * @param model
30: * theme model
31: * @param buttonOK
32: * OK button
33: */
34: public IMessageService(String name, JTextField text,
35: DefaultComboBoxModel model, JButton buttonOK) {
36: super (MessageServiceMBean.class, name);
37: text.getDocument().addDocumentListener(this );
38: this .text = text;
39: this .model = model;
40: buttonOK.setEnabled(false);
41: buttonOK.addActionListener(this );
42: this .buttonOK = buttonOK;
43: }
44:
45: public void actionPerformed(ActionEvent e) {
46: if (e.getSource() == buttonOK) {
47: buttonOK.setEnabled(false);
48: MessageService s = new MessageService();
49: s.setText(text.getText());
50: IMessageTheme t = (IMessageTheme) model.getSelectedItem();
51: s.setTheme(t.theme);
52: s.setUrl(t.transformer);
53: try {
54: setAttribute(MessageServiceMBean.OPTIONS, s);
55: } catch (Exception ex) {
56: Start.logger.log(Level.SEVERE, ex.getMessage(), ex);
57: }
58: } else
59: update();
60: }
61:
62: public void insertUpdate(DocumentEvent e) {
63: update();
64: }
65:
66: public void removeUpdate(DocumentEvent e) {
67: update();
68: }
69:
70: public void changedUpdate(DocumentEvent e) {
71: update();
72: }
73:
74: private void update() {
75: buttonOK.setEnabled(true);
76: }
77:
78: protected void otherNotification(String type, Object value) {
79: text.setText(((MessageService) value).getText());
80: for (int i = 0; i < model.getSize(); i++) {
81: Object o = model.getElementAt(i);
82: if (((IMessageTheme) o).theme
83: .equals(((MessageService) value).getTheme())) {
84: model.setSelectedItem(o);
85: break;
86: }
87: }
88: }
89: }
|