001: package vicazh.hyperpool.stream.net;
002:
003: import javax.swing.*;
004: import javax.swing.event.*;
005: import java.awt.*;
006: import java.awt.event.*;
007: import java.beans.*;
008: import java.util.logging.*;
009: import vicazh.hyperpool.*;
010: import vicazh.hyperpool.Start;
011: import java.io.*;
012:
013: /**
014: * The graphic in service
015: *
016: * @author Victor Zhigunov
017: * @version 0.4.0
018: */
019: public class IInService extends IService implements InServiceMBean,
020: ActionListener, DocumentListener, PropertyChangeListener {
021: private JTextField textHost;
022:
023: private JFormattedTextField textPort;
024:
025: private JButton buttonOK;
026:
027: private JDialog dialog;
028:
029: private JOptionPane optionPane;
030:
031: /**
032: * @param name
033: * service name
034: * @param textPort
035: * port text field
036: * @param buttonOK
037: * OK button
038: * @param dialog
039: * options dialog
040: */
041: public IInService(String name, JTextField textHost,
042: JFormattedTextField textPort, JButton buttonOK,
043: JDialog dialog) {
044: super (InServiceMBean.class, name);
045: this .textHost = textHost;
046: textPort.getDocument().addDocumentListener(this );
047: this .textPort = textPort;
048: buttonOK.setEnabled(false);
049: buttonOK.addActionListener(this );
050: this .buttonOK = buttonOK;
051: this .dialog = dialog;
052: optionPane = (JOptionPane) dialog.getContentPane();
053: optionPane.addPropertyChangeListener(this );
054: }
055:
056: public void actionPerformed(ActionEvent e) {
057: buttonOK.setEnabled(false);
058: try {
059: setAttribute(InServiceMBean.PORT, textPort.getValue());
060: } catch (IOException ex) {
061: dialog.setLocationRelativeTo(dialog.getOwner());
062: dialog.setVisible(true);
063: Object v = optionPane.getValue();
064: if (v == JOptionPane.UNINITIALIZED_VALUE)
065: return;
066: optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
067: } catch (Exception ex) {
068: Start.logger.log(Level.SEVERE, ex.getMessage(), ex);
069: }
070: }
071:
072: public void insertUpdate(DocumentEvent e) {
073: update();
074: }
075:
076: public void removeUpdate(DocumentEvent e) {
077: update();
078: }
079:
080: public void changedUpdate(DocumentEvent e) {
081: update();
082: }
083:
084: private void update() {
085: buttonOK.setEnabled(true);
086: }
087:
088: public void updateUI() {
089: SwingUtilities.updateComponentTreeUI(dialog);
090: }
091:
092: public void propertyChange(PropertyChangeEvent e) {
093: Component c = ((JComponent) e.getSource())
094: .getTopLevelAncestor();
095: String prop = e.getPropertyName();
096: if (c.isVisible()
097: && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop
098: .equals(JOptionPane.INPUT_VALUE_PROPERTY)))
099: c.setVisible(false);
100: }
101:
102: protected void currentNotification(String type, Object value) {
103: if (type.equals(ElementMBean.INIT))
104: textHost.setText((String) value);
105: }
106:
107: protected void otherNotification(String type, Object value) {
108: textPort.setValue(value);
109: }
110: }
|