src/share/classes/sun/tools/jconsole/inspector/XMBeanNotifications.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole.inspector;
  27 
  28 import javax.swing.*;
  29 import javax.swing.event.*;
  30 import javax.swing.table.*;
  31 import javax.swing.tree.*;
  32 import java.awt.Font;
  33 
  34 import java.text.SimpleDateFormat;
  35 
  36 import java.awt.Component;
  37 import java.awt.EventQueue;
  38 import java.awt.event.*;
  39 import java.awt.Dimension;
  40 import java.util.*;
  41 import java.io.*;
  42 import java.lang.reflect.Array;
  43 
  44 import javax.management.*;
  45 import javax.management.openmbean.CompositeData;
  46 import javax.management.openmbean.TabularData;
  47 
  48 import sun.tools.jconsole.JConsole;
  49 import sun.tools.jconsole.Resources;
  50 
  51 @SuppressWarnings("serial")
  52 public class XMBeanNotifications extends JTable implements NotificationListener {
  53 
  54     private final static String[] columnNames = {
  55         Resources.getText("TimeStamp"),
  56         Resources.getText("Type"),
  57         Resources.getText("UserData"),
  58         Resources.getText("SeqNum"),
  59         Resources.getText("Message"),
  60         Resources.getText("Event"),
  61         Resources.getText("Source")
  62     };
  63     private HashMap<ObjectName, XMBeanNotificationsListener> listeners =
  64             new HashMap<ObjectName, XMBeanNotificationsListener>();
  65     private volatile boolean subscribed;
  66     private XMBeanNotificationsListener currentListener;
  67     public final static String NOTIFICATION_RECEIVED_EVENT =
  68             "jconsole.xnotification.received";
  69     private List<NotificationListener> notificationListenersList;
  70     private volatile boolean enabled;
  71     private Font normalFont,  boldFont;
  72     private int rowMinHeight = -1;
  73     private TableCellEditor userDataEditor = new UserDataCellEditor();
  74     private NotifMouseListener mouseListener = new NotifMouseListener();
  75     private SimpleDateFormat timeFormater = new SimpleDateFormat("HH:mm:ss:SSS");
  76     private static TableCellEditor editor =
  77             new Utils.ReadOnlyTableCellEditor(new JTextField());
  78 
  79     public XMBeanNotifications() {
  80         super(new TableSorter(columnNames, 0));
  81         setColumnSelectionAllowed(false);


 166     @Override
 167     public synchronized TableCellRenderer getCellRenderer(int row, int column) {
 168         //In case we have a repaint thread that is in the process of
 169         //repainting an obsolete table, just ignore the call.
 170         //It can happen when MBean selection is switched at a very quick rate
 171         if (row >= getRowCount()) {
 172             return null;
 173         }
 174 
 175         DefaultTableCellRenderer renderer;
 176         String toolTip = null;
 177         UserDataCell cell = getUserDataCell(row, column);
 178         if (cell != null && cell.isInited()) {
 179             renderer = (DefaultTableCellRenderer) cell.getRenderer();
 180         } else {
 181             renderer =
 182                     (DefaultTableCellRenderer) super.getCellRenderer(row, column);
 183         }
 184 
 185         if (cell != null) {
 186             toolTip = Resources.getText("Double click to expand/collapse") +
 187                     ". " + cell.toString();
 188         } else {
 189             Object val =
 190                     ((DefaultTableModel) getModel()).getValueAt(row, column);
 191             if (val != null) {
 192                 toolTip = val.toString();
 193             }
 194         }
 195 
 196         renderer.setToolTipText(toolTip);
 197 
 198         return renderer;
 199     }
 200 
 201     // Call on EDT
 202     private UserDataCell getUserDataCell(int row, int column) {
 203         Object obj = ((DefaultTableModel) getModel()).getValueAt(row, column);
 204         if (obj instanceof UserDataCell) {
 205             return (UserDataCell) obj;
 206         }


 582         @Override
 583         public boolean stopCellEditing() {
 584             int editingRow = getEditingRow();
 585             int editingColumn = getEditingColumn();
 586             if (editingColumn == 2) {
 587                 Object obj = getModel().getValueAt(editingRow, editingColumn);
 588                 if (obj instanceof UserDataCell) {
 589                     UserDataCell cell = (UserDataCell) obj;
 590                     if (cell.isMaximized()) {
 591                         cancelCellEditing();
 592                         return true;
 593                     }
 594                 }
 595             }
 596             return super.stopCellEditing();
 597         }
 598     }
 599 
 600     class XMBeanNotificationsListener implements NotificationListener {
 601 
 602         private String[] columnNames;
 603         private XMBean xmbean;
 604         private DefaultMutableTreeNode node;
 605         private volatile long received;
 606         private XMBeanNotifications notifications;
 607         private volatile boolean unregistered;
 608         private ArrayList<Object[]> data = new ArrayList<Object[]>();
 609 
 610         public XMBeanNotificationsListener(
 611                 XMBeanNotifications notifications,
 612                 XMBean xmbean,
 613                 DefaultMutableTreeNode node,
 614                 String[] columnNames) {
 615             this.notifications = notifications;
 616             this.xmbean = xmbean;
 617             this.node = node;
 618             this.columnNames = columnNames;
 619             register(node);
 620         }
 621 
 622         public synchronized List<Object[]> getData() {
 623             return data;
 624         }
 625 
 626         public synchronized void clear() {
 627             data.clear();
 628             received = 0;
 629         }
 630 
 631         public synchronized boolean isRegistered() {
 632             return !unregistered;
 633         }
 634 
 635         public synchronized void unregister() {
 636             try {
 637                 xmbean.getMBeanServerConnection().removeNotificationListener(
 638                         xmbean.getObjectName(), this, null, null);




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.tools.jconsole.inspector;
  27 
  28 import javax.swing.*;

  29 import javax.swing.table.*;
  30 import javax.swing.tree.*;
  31 import java.awt.Font;
  32 
  33 import java.text.SimpleDateFormat;
  34 
  35 import java.awt.Component;
  36 import java.awt.EventQueue;
  37 import java.awt.event.*;
  38 import java.awt.Dimension;
  39 import java.util.*;
  40 import java.io.*;
  41 import java.lang.reflect.Array;
  42 
  43 import javax.management.*;
  44 import javax.management.openmbean.CompositeData;
  45 import javax.management.openmbean.TabularData;
  46 
  47 import sun.tools.jconsole.JConsole;
  48 import sun.tools.jconsole.resources.Messages;
  49 
  50 @SuppressWarnings("serial")
  51 public class XMBeanNotifications extends JTable implements NotificationListener {
  52 
  53     private final static String[] columnNames = {
  54         Messages.TIME_STAMP,
  55         Messages.TYPE,
  56         Messages.USER_DATA,
  57         Messages.SEQ_NUM,
  58         Messages.MESSAGE,
  59         Messages.EVENT,
  60         Messages.SOURCE
  61     };
  62     private HashMap<ObjectName, XMBeanNotificationsListener> listeners =
  63             new HashMap<ObjectName, XMBeanNotificationsListener>();
  64     private volatile boolean subscribed;
  65     private XMBeanNotificationsListener currentListener;
  66     public final static String NOTIFICATION_RECEIVED_EVENT =
  67             "jconsole.xnotification.received";
  68     private List<NotificationListener> notificationListenersList;
  69     private volatile boolean enabled;
  70     private Font normalFont,  boldFont;
  71     private int rowMinHeight = -1;
  72     private TableCellEditor userDataEditor = new UserDataCellEditor();
  73     private NotifMouseListener mouseListener = new NotifMouseListener();
  74     private SimpleDateFormat timeFormater = new SimpleDateFormat("HH:mm:ss:SSS");
  75     private static TableCellEditor editor =
  76             new Utils.ReadOnlyTableCellEditor(new JTextField());
  77 
  78     public XMBeanNotifications() {
  79         super(new TableSorter(columnNames, 0));
  80         setColumnSelectionAllowed(false);


 165     @Override
 166     public synchronized TableCellRenderer getCellRenderer(int row, int column) {
 167         //In case we have a repaint thread that is in the process of
 168         //repainting an obsolete table, just ignore the call.
 169         //It can happen when MBean selection is switched at a very quick rate
 170         if (row >= getRowCount()) {
 171             return null;
 172         }
 173 
 174         DefaultTableCellRenderer renderer;
 175         String toolTip = null;
 176         UserDataCell cell = getUserDataCell(row, column);
 177         if (cell != null && cell.isInited()) {
 178             renderer = (DefaultTableCellRenderer) cell.getRenderer();
 179         } else {
 180             renderer =
 181                     (DefaultTableCellRenderer) super.getCellRenderer(row, column);
 182         }
 183 
 184         if (cell != null) {
 185             toolTip = Messages.DOUBLE_CLICK_TO_EXPAND_FORWARD_SLASH_COLLAPSE+
 186                     ". " + cell.toString();
 187         } else {
 188             Object val =
 189                     ((DefaultTableModel) getModel()).getValueAt(row, column);
 190             if (val != null) {
 191                 toolTip = val.toString();
 192             }
 193         }
 194 
 195         renderer.setToolTipText(toolTip);
 196 
 197         return renderer;
 198     }
 199 
 200     // Call on EDT
 201     private UserDataCell getUserDataCell(int row, int column) {
 202         Object obj = ((DefaultTableModel) getModel()).getValueAt(row, column);
 203         if (obj instanceof UserDataCell) {
 204             return (UserDataCell) obj;
 205         }


 581         @Override
 582         public boolean stopCellEditing() {
 583             int editingRow = getEditingRow();
 584             int editingColumn = getEditingColumn();
 585             if (editingColumn == 2) {
 586                 Object obj = getModel().getValueAt(editingRow, editingColumn);
 587                 if (obj instanceof UserDataCell) {
 588                     UserDataCell cell = (UserDataCell) obj;
 589                     if (cell.isMaximized()) {
 590                         cancelCellEditing();
 591                         return true;
 592                     }
 593                 }
 594             }
 595             return super.stopCellEditing();
 596         }
 597     }
 598 
 599     class XMBeanNotificationsListener implements NotificationListener {
 600 

 601         private XMBean xmbean;
 602         private DefaultMutableTreeNode node;
 603         private volatile long received;
 604         private XMBeanNotifications notifications;
 605         private volatile boolean unregistered;
 606         private ArrayList<Object[]> data = new ArrayList<Object[]>();
 607 
 608         public XMBeanNotificationsListener(
 609                 XMBeanNotifications notifications,
 610                 XMBean xmbean,
 611                 DefaultMutableTreeNode node,
 612                 String[] columnNames) {
 613             this.notifications = notifications;
 614             this.xmbean = xmbean;
 615             this.node = node;

 616             register(node);
 617         }
 618 
 619         public synchronized List<Object[]> getData() {
 620             return data;
 621         }
 622 
 623         public synchronized void clear() {
 624             data.clear();
 625             received = 0;
 626         }
 627 
 628         public synchronized boolean isRegistered() {
 629             return !unregistered;
 630         }
 631 
 632         public synchronized void unregister() {
 633             try {
 634                 xmbean.getMBeanServerConnection().removeNotificationListener(
 635                         xmbean.getObjectName(), this, null, null);