| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package net.wotonomy.ui.swing; |
| 20 |
|
|
| 21 |
|
import java.awt.BorderLayout; |
| 22 |
|
import java.awt.Insets; |
| 23 |
|
import java.awt.event.ActionEvent; |
| 24 |
|
import java.awt.event.ActionListener; |
| 25 |
|
import java.awt.event.MouseEvent; |
| 26 |
|
import java.awt.event.MouseListener; |
| 27 |
|
import java.text.SimpleDateFormat; |
| 28 |
|
import java.util.Date; |
| 29 |
|
|
| 30 |
|
import javax.swing.JFrame; |
| 31 |
|
import javax.swing.JMenuItem; |
| 32 |
|
import javax.swing.JPanel; |
| 33 |
|
import javax.swing.JPopupMenu; |
| 34 |
|
import javax.swing.JScrollPane; |
| 35 |
|
import javax.swing.JTable; |
| 36 |
|
import javax.swing.border.EmptyBorder; |
| 37 |
|
import javax.swing.table.TableColumn; |
| 38 |
|
|
| 39 |
|
import net.wotonomy.foundation.NSMutableArray; |
| 40 |
|
import net.wotonomy.foundation.NSNotification; |
| 41 |
|
import net.wotonomy.foundation.NSNotificationCenter; |
| 42 |
|
import net.wotonomy.foundation.NSSelector; |
| 43 |
|
import net.wotonomy.ui.EOAssociation; |
| 44 |
|
import net.wotonomy.ui.EODisplayGroup; |
| 45 |
|
import net.wotonomy.ui.swing.components.FormattedCellRenderer; |
| 46 |
|
import net.wotonomy.ui.swing.util.ObjectInspector; |
| 47 |
|
import net.wotonomy.ui.swing.util.StackTraceInspector; |
| 48 |
|
import net.wotonomy.ui.swing.util.WindowUtilities; |
| 49 |
|
import net.wotonomy.control.internal.Surrogate; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
public class NotificationInspector |
| 60 |
|
implements MouseListener, ActionListener |
| 61 |
|
{ |
| 62 |
|
protected JTable table; |
| 63 |
|
protected JPopupMenu popupMenu; |
| 64 |
|
protected EODisplayGroup displayGroup; |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
static public final String COPY = "COPY"; |
| 68 |
|
|
| 69 |
|
protected static final String CLEAR_ALL = "Clear All"; |
| 70 |
|
protected static final String CLEAR_SELECTED = "Clear Selected"; |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
public NotificationInspector() |
| 77 |
|
{ |
| 78 |
0 |
this( NSNotificationCenter.defaultCenter() ); |
| 79 |
0 |
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
public NotificationInspector( NSNotificationCenter aCenter ) |
| 85 |
|
{ |
| 86 |
0 |
this( aCenter, null, null ); |
| 87 |
0 |
} |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
public NotificationInspector( String notificationName, Object anObject ) |
| 94 |
|
{ |
| 95 |
0 |
this( NSNotificationCenter.defaultCenter(), |
| 96 |
0 |
notificationName, anObject ); |
| 97 |
0 |
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
0 |
public NotificationInspector( NSNotificationCenter aCenter, |
| 104 |
|
String notificationName, Object anObject ) |
| 105 |
0 |
{ |
| 106 |
|
|
| 107 |
0 |
NSNotification.showStack = true; |
| 108 |
|
|
| 109 |
|
|
| 110 |
0 |
NSSelector handleNotification = |
| 111 |
0 |
new NSSelector( "handleNotification", |
| 112 |
0 |
new Class[] { NSNotification.class } ); |
| 113 |
0 |
aCenter.addObserver( |
| 114 |
0 |
this, handleNotification, notificationName, anObject ); |
| 115 |
|
|
| 116 |
0 |
table = new JTable(); |
| 117 |
|
|
| 118 |
0 |
popupMenu = new JPopupMenu(); |
| 119 |
0 |
JMenuItem menuItem = popupMenu.add( CLEAR_SELECTED ); |
| 120 |
0 |
menuItem.addActionListener( this ); |
| 121 |
0 |
menuItem = popupMenu.add( CLEAR_ALL ); |
| 122 |
0 |
menuItem.addActionListener( this ); |
| 123 |
|
|
| 124 |
0 |
displayGroup = new EODisplayGroup(); |
| 125 |
|
|
| 126 |
|
TableColumn column; |
| 127 |
|
TableColumnAssociation assoc; |
| 128 |
|
|
| 129 |
0 |
column = new TableColumn(); |
| 130 |
0 |
column.setHeaderValue( "Time" ); |
| 131 |
0 |
column.setCellRenderer( new FormattedCellRenderer( new SimpleDateFormat( "hh:mm:ss:SS" ) ) ); |
| 132 |
0 |
column.setPreferredWidth( 90 ); |
| 133 |
0 |
column.setMaxWidth( 90 ); |
| 134 |
|
|
| 135 |
0 |
assoc = new TableColumnAssociation( column ); |
| 136 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "time" ); |
| 137 |
0 |
assoc.setTable( table ); |
| 138 |
0 |
assoc.establishConnection(); |
| 139 |
|
|
| 140 |
0 |
column = new TableColumn(); |
| 141 |
0 |
column.setHeaderValue( "Type" ); |
| 142 |
|
|
| 143 |
0 |
assoc = new TableColumnAssociation( column ); |
| 144 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "name" ); |
| 145 |
0 |
assoc.setTable( table ); |
| 146 |
0 |
assoc.establishConnection(); |
| 147 |
|
|
| 148 |
0 |
column = new TableColumn(); |
| 149 |
0 |
column.setHeaderValue( "Object" ); |
| 150 |
|
|
| 151 |
0 |
assoc = new TableColumnAssociation( column ); |
| 152 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "objectString" ); |
| 153 |
0 |
assoc.setTable( table ); |
| 154 |
0 |
assoc.establishConnection(); |
| 155 |
|
|
| 156 |
0 |
column = new TableColumn(); |
| 157 |
0 |
column.setHeaderValue( "Info" ); |
| 158 |
|
|
| 159 |
0 |
assoc = new TableColumnAssociation( column ); |
| 160 |
0 |
assoc.bindAspect( EOAssociation.ValueAspect, displayGroup, "userInfoString" ); |
| 161 |
0 |
assoc.setTable( table ); |
| 162 |
0 |
assoc.establishConnection(); |
| 163 |
|
|
| 164 |
0 |
initLayout(); |
| 165 |
0 |
} |
| 166 |
|
|
| 167 |
|
protected void initLayout() |
| 168 |
|
{ |
| 169 |
0 |
table.addMouseListener( this ); |
| 170 |
|
|
| 171 |
0 |
JPanel panel = new JPanel(); |
| 172 |
0 |
panel.setBorder( new EmptyBorder( new Insets( 10, 10, 10, 10 ) ) ); |
| 173 |
0 |
panel.setLayout( new BorderLayout( 10, 10 ) ); |
| 174 |
|
|
| 175 |
0 |
JScrollPane scrollPane = new JScrollPane( table ); |
| 176 |
|
|
| 177 |
0 |
panel.add( scrollPane, BorderLayout.CENTER ); |
| 178 |
|
|
| 179 |
0 |
JFrame window = new JFrame(); |
| 180 |
0 |
window.setTitle( "Notification Inspector" ); |
| 181 |
0 |
window.getContentPane().add( panel ); |
| 182 |
|
|
| 183 |
|
|
| 184 |
0 |
window.setSize( 800, 400 ); |
| 185 |
0 |
WindowUtilities.cascade( window ); |
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
|
|
| 190 |
0 |
window.show(); |
| 191 |
0 |
} |
| 192 |
|
|
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| 196 |
|
public void handleNotification( NSNotification aNotification ) |
| 197 |
|
{ |
| 198 |
0 |
Surrogate s = new Surrogate( new Object[] { aNotification } ); |
| 199 |
0 |
s.directPut( "time", new Date() ); |
| 200 |
0 |
s.directPut( "objectString", ""+aNotification.object() ); |
| 201 |
0 |
s.directPut( "userInfoString", ""+aNotification.userInfo() ); |
| 202 |
0 |
displayGroup.insertObjectAtIndex( s, 0 ); |
| 203 |
0 |
} |
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
|
| 209 |
|
|
| 210 |
|
public void actionPerformed( ActionEvent e ) |
| 211 |
|
{ |
| 212 |
0 |
if ( CLEAR_SELECTED.equals( e.getActionCommand() ) ) |
| 213 |
|
{ |
| 214 |
0 |
NSMutableArray objects = new NSMutableArray( displayGroup.allObjects() ); |
| 215 |
0 |
objects.removeAll( displayGroup.selectedObjects() ); |
| 216 |
0 |
displayGroup.setObjectArray( objects ); |
| 217 |
0 |
displayGroup.updateDisplayedObjects(); |
| 218 |
0 |
} |
| 219 |
0 |
else if ( CLEAR_ALL.equals( e.getActionCommand() ) ) |
| 220 |
|
{ |
| 221 |
0 |
displayGroup.setObjectArray( null ); |
| 222 |
0 |
displayGroup.updateDisplayedObjects(); |
| 223 |
|
} |
| 224 |
0 |
} |
| 225 |
|
|
| 226 |
|
|
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
|
| 231 |
|
|
| 232 |
|
public void mouseClicked(MouseEvent e) |
| 233 |
|
{ |
| 234 |
0 |
if ( e.getSource() == table ) |
| 235 |
|
{ |
| 236 |
0 |
if ( e.getClickCount() > 1 ) |
| 237 |
|
{ |
| 238 |
0 |
int row = table.rowAtPoint( e.getPoint() ); |
| 239 |
0 |
int col = table.columnAtPoint( e.getPoint() ); |
| 240 |
0 |
col = table.convertColumnIndexToModel( col ); |
| 241 |
|
|
| 242 |
0 |
if ( row == -1 ) return; |
| 243 |
|
|
| 244 |
0 |
if ( col == 0 ) |
| 245 |
|
{ |
| 246 |
0 |
new StackTraceInspector( ( (NSNotification) ( (Surrogate) |
| 247 |
0 |
displayGroup.displayedObjects().objectAtIndex( row ) ).getDelegate() ).stackTrace() ); |
| 248 |
0 |
} |
| 249 |
|
else |
| 250 |
0 |
if ( col == 2 ) |
| 251 |
|
{ |
| 252 |
0 |
new ObjectInspector( ( (NSNotification) ( (Surrogate) |
| 253 |
0 |
displayGroup.displayedObjects().objectAtIndex( row ) ).getDelegate() ).object() ); |
| 254 |
0 |
} |
| 255 |
|
else |
| 256 |
0 |
if ( col == 3 ) |
| 257 |
|
{ |
| 258 |
0 |
new ObjectInspector( ( (NSNotification) ( (Surrogate) |
| 259 |
0 |
displayGroup.displayedObjects().objectAtIndex( row ) ).getDelegate() ).userInfo() ); |
| 260 |
0 |
} |
| 261 |
|
else |
| 262 |
|
{ |
| 263 |
0 |
new ObjectInspector( ( (Surrogate) |
| 264 |
0 |
displayGroup.displayedObjects().objectAtIndex( row ) ).getDelegate() ); |
| 265 |
|
} |
| 266 |
0 |
} |
| 267 |
|
else |
| 268 |
|
{ |
| 269 |
|
|
| 270 |
0 |
if ( e.isPopupTrigger() ) |
| 271 |
|
{ |
| 272 |
0 |
popupMenu.show( table, e.getX(), e.getY() ); |
| 273 |
|
} |
| 274 |
|
} |
| 275 |
|
} |
| 276 |
0 |
} |
| 277 |
|
|
| 278 |
|
public void mouseReleased(MouseEvent e) |
| 279 |
|
{ |
| 280 |
0 |
if ( e.getSource() == table ) |
| 281 |
|
{ |
| 282 |
0 |
if ( e.isPopupTrigger() && ( e.getClickCount() == 1 ) ) |
| 283 |
|
{ |
| 284 |
0 |
popupMenu.show( table, e.getX(), e.getY() ); |
| 285 |
|
} |
| 286 |
|
} |
| 287 |
0 |
} |
| 288 |
|
|
| 289 |
|
public void mousePressed(MouseEvent e) |
| 290 |
|
{ |
| 291 |
0 |
if ( e.getSource() == table ) |
| 292 |
|
{ |
| 293 |
0 |
if ( e.isPopupTrigger() && ( e.getClickCount() == 1 ) ) |
| 294 |
|
{ |
| 295 |
0 |
popupMenu.show( table, e.getX(), e.getY() ); |
| 296 |
|
} |
| 297 |
|
} |
| 298 |
0 |
} |
| 299 |
|
|
| 300 |
0 |
public void mouseEntered(MouseEvent e) {} |
| 301 |
0 |
public void mouseExited(MouseEvent e) {} |
| 302 |
|
|
| 303 |
|
} |
| 304 |
|
|
| 305 |
|
|
| 306 |
|
|
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
|
|
| 311 |
|
|
| 312 |
|
|
| 313 |
|
|
| 314 |
|
|
| 315 |
|
|
| 316 |
|
|
| 317 |
|
|
| 318 |
|
|
| 319 |
|
|
| 320 |
|
|
| 321 |
|
|
| 322 |
|
|
| 323 |
|
|
| 324 |
|
|
| 325 |
|
|
| 326 |
|
|
| 327 |
|
|
| 328 |
|
|
| 329 |
|
|
| 330 |
|
|
| 331 |
|
|
| 332 |
|
|
| 333 |
|
|