public Listener()

in tcpmon/src/main/java/org/apache/axis/utils/tcpmon.java [1318:1620]


        public Listener(JTabbedPane _notebook, String name,
            int listenPort, String host, int targetPort,
            boolean isProxy, SlowLinkSimulator slowLink) {
            notebook = _notebook ;
            if ( name == null ) {
                name = getMessage("port01", "Port") + " " + listenPort ;
            }
            //set the slow link to the passed down link
            if(slowLink!=null) {
                this.slowLink=slowLink;
            } else {
                //or make up a no-op one.
                this.slowLink=new SlowLinkSimulator(0,0);
            }
            this.setLayout( new BorderLayout() );

            // 1st component is just a row of labels and 1-line entry fields
            /////////////////////////////////////////////////////////////////////
            JPanel top = new JPanel();

            top.setLayout( new BoxLayout(top, BoxLayout.X_AXIS) );
            top.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            final String start = getMessage("start00", "Start");

            top.add( stopButton = new JButton( start ) );
            top.add( Box.createRigidArea(new Dimension(5, 0)) );
            top.add( new JLabel( "  " + getMessage("listenPort01", "Listen Port:") + " ", SwingConstants.RIGHT ) );
            top.add( portField = new JTextField( "" + listenPort, 4 ) );
            top.add( new JLabel( "  " + getMessage("host00", "Host:"), SwingConstants.RIGHT ) );
            top.add( hostField = new JTextField( host, 30 ) );
            top.add( new JLabel( "  " + getMessage("port02", "Port:") + " ", SwingConstants.RIGHT ) );
            top.add( tPortField = new JTextField( "" + targetPort, 4 ) );
            top.add( Box.createRigidArea(new Dimension(5, 0)) );
            top.add( isProxyBox = new JCheckBox(getMessage("proxy00", "Proxy")) );

            isProxyBox.addChangeListener( new BasicButtonListener(isProxyBox) {
                    public void stateChanged(ChangeEvent event) {
                        JCheckBox box = (JCheckBox) event.getSource();
                        boolean state = box.isSelected();

                        tPortField.setEnabled( !state );
                        hostField.setEnabled( !state );
                    }
                }
            );

            isProxyBox.setSelected(isProxy);

            portField.setEditable(false);
            portField.setMaximumSize(new Dimension(50, Short.MAX_VALUE) );
            hostField.setEditable(false);
            hostField.setMaximumSize(new Dimension(85, Short.MAX_VALUE) );
            tPortField.setEditable(false);
            tPortField.setMaximumSize(new Dimension(50, Short.MAX_VALUE) );

            stopButton.addActionListener( new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        if ( getMessage("stop00", "Stop").equals(event.getActionCommand()) ) {
                            stop();
                        }
                        if ( start.equals(event.getActionCommand()) ) {
                            start();
                        }
                    }
                }
            );

            this.add( top, BorderLayout.NORTH );

            // 2nd component is a split pane with a table on the top
            // and the request/response text areas on the bottom
            /////////////////////////////////////////////////////////////////////

            tableModel = new DefaultTableModel(new String[] {
                    getMessage("state00", "State"),
                    getMessage("time00", "Time"),
                    getMessage("requestHost00", "Request Host"),
                    getMessage("targetHost", "Target Host"),
                    getMessage("request00", "Request...")
                } , 0 );

            tableModel.addRow( new Object[] {
                    "---", getMessage("mostRecent00", "Most Recent"), "---", "---", "---"
                }
            );

            connectionTable = new JTable(1, 2);
            connectionTable.setModel( tableModel );
            connectionTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            // Reduce the STATE column and increase the REQ column
            TableColumn col ;

            col = connectionTable.getColumnModel().getColumn(STATE_COLUMN);
            col.setMaxWidth( col.getPreferredWidth() / 2 );
            col = connectionTable.getColumnModel().getColumn(REQ_COLUMN);
            col.setPreferredWidth( col.getPreferredWidth() * 2 );


            ListSelectionModel sel = connectionTable.getSelectionModel();

            sel.addListSelectionListener( new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent event) {
                        if (event.getValueIsAdjusting()) {
                            return ;
                        }
                        ListSelectionModel m = (ListSelectionModel) event.getSource();
                        int divLoc = outPane.getDividerLocation();

                        if (m.isSelectionEmpty()) {
                            setLeft( new JLabel(" " + getMessage("wait00", "Waiting for Connection...") ) );
                            setRight( new JLabel("") );
                            removeButton.setEnabled(false);
                            removeAllButton.setEnabled(false);
                            saveButton.setEnabled(false);
                            resendButton.setEnabled(false);
                        }
                        else {
                            int row = m.getLeadSelectionIndex();

                            if ( row == 0 ) {
                                if ( connections.size() == 0 ) {
                                    setLeft(new JLabel(" " + getMessage("wait00", "Waiting for connection...")));
                                    setRight(new JLabel(""));
                                    removeButton.setEnabled(false);
                                    removeAllButton.setEnabled(false);
                                    saveButton.setEnabled(false);
                                    resendButton.setEnabled(false);
                                }
                                else {
                                    Connection conn = (Connection) connections.lastElement();

                                    setLeft( conn.inputScroll );
                                    setRight( conn.outputScroll );
                                    removeButton.setEnabled(false);
                                    removeAllButton.setEnabled(true);
                                    saveButton.setEnabled(true);
                                    resendButton.setEnabled(true);
                                }
                            }
                            else {
                                Connection conn = (Connection) connections.get(row - 1);

                                setLeft( conn.inputScroll );
                                setRight( conn.outputScroll );
                                removeButton.setEnabled(true);
                                removeAllButton.setEnabled(true);
                                saveButton.setEnabled(true);
                                resendButton.setEnabled(true);
                            }
                        }
                        outPane.setDividerLocation(divLoc);
                    }
                }
            );

            JPanel  tablePane = new JPanel();

            tablePane.setLayout( new BorderLayout() );

            JScrollPane tableScrollPane = new JScrollPane( connectionTable );

            tablePane.add( tableScrollPane, BorderLayout.CENTER );
            JPanel buttons = new JPanel();

            buttons.setLayout( new BoxLayout(buttons, BoxLayout.X_AXIS) );
            buttons.setBorder( BorderFactory.createEmptyBorder(5, 5, 5, 5) );
            final String removeSelected = getMessage("removeSelected00", "Remove Selected");

            buttons.add( removeButton = new JButton(removeSelected) );
            buttons.add( Box.createRigidArea(new Dimension(5, 0)) );
            final String removeAll = getMessage("removeAll00", "Remove All");

            buttons.add( removeAllButton = new JButton(removeAll) );
            tablePane.add( buttons, BorderLayout.SOUTH );

            removeButton.setEnabled( false );
            removeButton.addActionListener( new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        if ( removeSelected.equals(event.getActionCommand()) ) {
                            remove();
                        }
                    }
                }
            );

            removeAllButton.setEnabled( false );
            removeAllButton.addActionListener( new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        if ( removeAll.equals(event.getActionCommand()) ) {
                            removeAll();
                        }
                    }
                }
            );

            // Add Response Section
            /////////////////////////////////////////////////////////////////////
            JPanel     pane2     = new JPanel();

            pane2.setLayout( new BorderLayout() );

            leftPanel = new JPanel();
            leftPanel.setAlignmentX( Component.LEFT_ALIGNMENT );
            leftPanel.setLayout( new BoxLayout(leftPanel, BoxLayout.Y_AXIS) );
            leftPanel.add( new JLabel("  " + getMessage("request01", "Request")) );
            leftPanel.add( new JLabel(" " + getMessage("wait01", "Waiting for connection") ));

            rightPanel = new JPanel();
            rightPanel.setLayout( new BoxLayout(rightPanel, BoxLayout.Y_AXIS) );
            rightPanel.add( new JLabel("  " + getMessage("response00", "Response")) );
            rightPanel.add( new JLabel("") );

            outPane = new JSplitPane(0, leftPanel, rightPanel );
            outPane.setDividerSize(4);
            pane2.add( outPane, BorderLayout.CENTER );

            JPanel bottomButtons = new JPanel();

            bottomButtons.setLayout( new BoxLayout(bottomButtons, BoxLayout.X_AXIS));
            bottomButtons.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            bottomButtons.add( xmlFormatBox = new JCheckBox( getMessage("xmlFormat00", "XML Format") ) );
            bottomButtons.add( numericBox = new JCheckBox( getMessage("numericEnc00", "Numeric" ) ) );
            bottomButtons.add( Box.createRigidArea(new Dimension(5, 0)) );
            final String save = getMessage("save00", "Save");

            bottomButtons.add( saveButton = new JButton( save ) );
            bottomButtons.add( Box.createRigidArea(new Dimension(5, 0)) );
            final String resend = getMessage("resend00", "Resend");

            bottomButtons.add( resendButton = new JButton( resend ) );
            bottomButtons.add( Box.createRigidArea(new Dimension(5, 0)) );
            final String switchStr = getMessage("switch00", "Switch Layout");

            bottomButtons.add( switchButton = new JButton( switchStr ) );
            bottomButtons.add( Box.createHorizontalGlue() );
            final String close = getMessage("close00", "Close");

            bottomButtons.add( closeButton = new JButton( close ) );
            pane2.add( bottomButtons, BorderLayout.SOUTH );

            saveButton.setEnabled( false );
            saveButton.addActionListener( new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        if ( save.equals(event.getActionCommand()) ) {
                            save();
                        }
                    }
                }
            );

            resendButton.setEnabled( false );
            resendButton.addActionListener( new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        if ( resend.equals(event.getActionCommand()) ) {
                            resend();
                        }
                    }
                }
            );

            switchButton.addActionListener( new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        if (switchStr.equals(event.getActionCommand()) ) {
                            int v = outPane.getOrientation();

                            if ( v == 0 ) {
                                // top/bottom
                                outPane.setOrientation(1);
                            }
                            else  {
                                // left/right
                                outPane.setOrientation(0);
                            }
                            outPane.setDividerLocation(0.5);
                        }
                    }
                }
            );

            closeButton.addActionListener( new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        if (close.equals(event.getActionCommand()) ) {
                            close();
                        }
                    }
                }
            );

            JSplitPane  pane1 = new JSplitPane( 0 );

            pane1.setDividerSize(4);
            pane1.setTopComponent( tablePane );
            pane1.setBottomComponent( pane2 );
            pane1.setDividerLocation( 150 );
            this.add( pane1, BorderLayout.CENTER );

            //
            ////////////////////////////////////////////////////////////////////
            sel.setSelectionInterval(0, 0);
            outPane.setDividerLocation( 150 );
            notebook.addTab( name, this );
            start();
        }