You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/01/28 12:56:08 UTC

svn commit: r738460 - in /webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon: Connection.java Listener.java

Author: veithen
Date: Wed Jan 28 11:56:07 2009
New Revision: 738460

URL: http://svn.apache.org/viewvc?rev=738460&view=rev
Log:
TCPMon Swing UI: Simplified the selection handling code and reduced the visibility of some of the attributes for better encapsulation.

Modified:
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java?rev=738460&r1=738459&r2=738460&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java Wed Jan 28 11:56:07 2009
@@ -18,7 +18,6 @@
 
 import javax.swing.JScrollPane;
 import javax.swing.JTextArea;
-import javax.swing.ListSelectionModel;
 
 import org.apache.ws.commons.tcpmon.core.AbstractConnection;
 
@@ -107,19 +106,7 @@
         inputScroll = new JScrollPane(inputText);
         outputText = new JTextArea(null, null, 20, 80);
         outputScroll = new JScrollPane(outputText);
-        ListSelectionModel lsm = listener.connectionTable.getSelectionModel();
-        if ((count == 0) || (lsm.getLeadSelectionIndex() == 0)) {
-            listener.outPane.setVisible(false);
-            int divLoc = listener.outPane.getDividerLocation();
-            listener.setLeft(inputScroll);
-            listener.setRight(outputScroll);
-            listener.removeButton.setEnabled(false);
-            listener.removeAllButton.setEnabled(true);
-            listener.saveButton.setEnabled(true);
-            listener.resendButton.setEnabled(true);
-            listener.outPane.setDividerLocation(divLoc);
-            listener.outPane.setVisible(true);
-        }
+        listener.handleSelection();
         inputWriter = new JTextAreaWriter(inputText);
         outputWriter = new JTextAreaWriter(outputText);
     }

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java?rev=738460&r1=738459&r2=738460&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java Wed Jan 28 11:56:07 2009
@@ -34,7 +34,6 @@
 import javax.swing.ListSelectionModel;
 import javax.swing.SwingConstants;
 import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
 import javax.swing.plaf.basic.BasicButtonListener;
@@ -96,12 +95,12 @@
     /**
      * Field removeButton
      */
-    public JButton removeButton = null;
+    private final JButton removeButton;
 
     /**
      * Field removeAllButton
      */
-    public JButton removeAllButton = null;
+    private final JButton removeAllButton;
 
     /**
      * Field xmlFormatBox
@@ -111,19 +110,19 @@
     /**
      * Field saveButton
      */
-    public JButton saveButton = null;
+    private final JButton saveButton;
 
     /**
      * Field resendButton
      */
-    public JButton resendButton = null;
+    private final JButton resendButton;
 
     private final JButton switchButton;
 
     /**
      * Field connectionTable
      */
-    public JTable connectionTable = null;
+    private final JTable connectionTable;
 
     /**
      * Field tableModel
@@ -133,7 +132,7 @@
     /**
      * Field outPane
      */
-    public JSplitPane outPane = null;
+    private final JSplitPane outPane;
 
     /**
      * Field sw
@@ -275,61 +274,9 @@
         ListSelectionModel sel = connectionTable.getSelectionModel();
         sel.addListSelectionListener(new ListSelectionListener() {
             public void valueChanged(ListSelectionEvent event) {
-                if (event.getValueIsAdjusting()) {
-                    return;
+                if (!event.getValueIsAdjusting()) {
+                    handleSelection();
                 }
-                ListSelectionModel m =
-                        (ListSelectionModel) event.getSource();
-                int divLoc = outPane.getDividerLocation();
-                if (m.isSelectionEmpty()) {
-                    setLeft(
-                            new JLabel(
-                                    " "
-                            +
-                            TCPMonBundle.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(
-                                            " "
-                                    +
-                                    TCPMonBundle.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();
@@ -453,12 +400,47 @@
                 Icons.LAYOUT_HORIZONTAL);  
     }
 
+    public void handleSelection() {
+        ListSelectionModel m = connectionTable.getSelectionModel();
+        int divLoc = outPane.getDividerLocation();
+        Connection conn;
+        if (m.isSelectionEmpty()) {
+            conn = null;
+            removeButton.setEnabled(false);
+        } else {
+            int row = m.getLeadSelectionIndex();
+            if (row == 0) {
+                if (connections.size() == 0) {
+                    conn = null;
+                } else {
+                    conn = (Connection) connections.lastElement();
+                }
+                removeButton.setEnabled(false);
+            } else {
+                conn = (Connection) connections.get(row - 1);
+                removeButton.setEnabled(true);
+            }
+        }
+        if (conn == null) {
+            setLeft(new JLabel(" " + TCPMonBundle.getMessage("wait00",
+                    "Waiting for Connection...")));
+            setRight(new JLabel(""));
+        } else {
+            setLeft(conn.inputScroll);
+            setRight(conn.outputScroll);
+        }
+        saveButton.setEnabled(conn != null);
+        resendButton.setEnabled(conn != null);
+        removeAllButton.setEnabled(!connections.isEmpty());
+        outPane.setDividerLocation(divLoc);
+    }
+
     /**
      * Method setLeft
      *
      * @param left
      */
-    public void setLeft(Component left) {
+    private void setLeft(Component left) {
         leftPanel.removeAll();
         leftPanel.add(left);
     }
@@ -468,7 +450,7 @@
      *
      * @param right
      */
-    public void setRight(Component right) {
+    private void setRight(Component right) {
         rightPanel.removeAll();
         rightPanel.add(right);
     }