1 package org.jacorb.ir.gui; 2 3 22 23 import javax.swing.*; 24 import javax.swing.table.*; 25 import javax.swing.tree.*; 26 import javax.swing.event.*; 27 28 import java.awt.*; 29 import java.awt.event.*; 30 31 import org.jacorb.ir.gui.typesystem.*; 32 33 37 38 class IRBrowser 39 extends JFrame 40 implements java.awt.event.WindowListener , 41 java.awt.event.MouseListener , 42 ListSelectionListener, 43 TreeSelectionListener, 44 ActionListener 45 { 46 47 JTable contentTable; 48 JSplitPane splitPane; 49 JTree treeView; 50 JTextArea textArea; 51 TypeSystem typeSystem; 52 TreeModel treeModel; 53 JMenuItem followTypeMenu; 54 private static final String title = "IRBrowser"; 55 56 59 60 public IRBrowser() 61 { 62 super(); 63 typeSystem = new org.jacorb.ir.gui.typesystem.remote.RemoteTypeSystem(); 64 initialize(); 65 } 66 67 70 71 public IRBrowser (String repositoryIOR) 72 { 73 super(); 74 typeSystem = 75 new org.jacorb.ir.gui.typesystem.remote.RemoteTypeSystem(repositoryIOR); 76 initialize(); 77 } 78 79 82 83 public void actionPerformed (java.awt.event.ActionEvent event) 84 { 85 NodeMapper nodeMapper = 86 (NodeMapper)contentTable.getModel().getValueAt(contentTable.getSelectedRow(),0); 87 TypeSystemNode typeSystemNode = nodeMapper.getNode(); 88 followTypeOf(typeSystemNode); 89 System.out.println("following type of "+typeSystemNode); 90 } 91 92 96 97 private void conn0(java.awt.event.WindowEvent arg1) 98 { 99 try 100 { 101 this.dispose(); 104 } 107 catch (java.lang.Throwable ivjExc) 108 { 109 handleException(ivjExc); 112 } 113 } 114 115 118 119 public void followTypeOf(TypeSystemNode typeSystemNode) 120 { 121 DefaultMutableTreeNode treeNode=null; 122 123 if ( typeSystemNode instanceof TypeAssociator ) 124 { 125 TypeSystemNode assTypeNode = 126 ((TypeAssociator)typeSystemNode).getAssociatedTypeSystemNode(); 127 if (assTypeNode.getModelRepresentant(treeModel)!=null) 128 { 129 treeNode = 130 (DefaultMutableTreeNode)assTypeNode.getModelRepresentant(treeModel); 131 } 132 } 133 if ( treeNode != null ) 134 { 135 DefaultTreeModel treeModel = 138 (DefaultTreeModel)treeView.getModel(); 139 TreePath fullTreePath = 140 new TreePath(treeModel.getPathToRoot(treeNode)); 141 142 treeView.scrollPathToVisible(fullTreePath); 143 treeView.setSelectionPath(fullTreePath); 145 treeView.validate(); 146 } 147 } 148 149 153 154 private void handleException(Throwable exception) 155 { 156 exception.printStackTrace(); 157 } 158 159 162 163 private void initConnections() 164 { 165 this.addWindowListener(this); 166 } 167 168 169 172 173 public void initialize() 174 { 175 setTitle(title); 177 178 splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); 179 180 DefaultTableModel tableModel = typeSystem.getTableModel(null); 182 contentTable = new JTable(tableModel); 183 contentTable.setAutoCreateColumnsFromModel(true); 184 contentTable.setColumnSelectionAllowed(false); 186 contentTable.setRowSelectionAllowed(true); 187 contentTable.setCellSelectionEnabled(false); 188 contentTable.removeEditor(); 189 contentTable.setShowGrid(false); 190 contentTable.setTableHeader(new javax.swing.table.JTableHeader (contentTable.getColumnModel())); 191 contentTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); 192 contentTable.setMinimumSize(new Dimension(100,100)); 195 contentTable.getSelectionModel().addListSelectionListener(this); 196 197 198 this.treeModel = typeSystem.getTreeModel(); 199 treeView = new JTree(treeModel); 201 treeView.setRootVisible(true); 203 treeView.setShowsRootHandles(true); 204 treeView.setMinimumSize(new Dimension(100,100)); 207 treeView.addTreeSelectionListener(this); 208 209 JScrollPane tableScrollPane = JTable.createScrollPaneForTable(contentTable); 210 JScrollPane treeScrollPane = new JScrollPane(treeView); 211 tableScrollPane.setMinimumSize(new java.awt.Dimension (100,100)); 213 treeScrollPane.setMinimumSize(new java.awt.Dimension (100,100)); 214 tableScrollPane.setPreferredSize(new java.awt.Dimension (100,100)); 215 treeScrollPane.setPreferredSize(new java.awt.Dimension (100,100)); 216 217 textArea = new JTextArea("Hallo, hallo!"); 218 textArea.setEditable(false); 219 textArea.setFont(new java.awt.Font ("sansserif",java.awt.Font.PLAIN,10)); 220 textArea.setRows(4); 221 textArea.setTabSize(15); 222 textArea.setBorder(BorderFactory.createLoweredBevelBorder()); 223 textArea.setMinimumSize(new java.awt.Dimension (100,100)); 224 textArea.setPreferredSize(new Dimension(600,90)); 225 227 splitPane.setLeftComponent(new JScrollPane(treeView)); 228 splitPane.setRightComponent(tableScrollPane); 229 splitPane.setDividerLocation(300); 231 232 Container contentPane = getContentPane(); 234 239 249 splitPane.setBounds(0,0,600,400-textArea.getPreferredSize().height); 252 textArea.setBounds(0,splitPane.bounds().height,600,textArea.getPreferredSize().height); 253 contentPane.setLayout(new BorderLayout()); 255 contentPane.add("Center",splitPane); 256 257 contentPane.add("South",textArea); 259 contentPane.setBackground(Color.white); 260 261 resize(600,400); 262 264 269 JMenuBar menuBar = new JMenuBar(); 270 JMenu menu = new JMenu("Navigate"); 271 menuBar.add(menu); 272 followTypeMenu = new JMenuItem("Follow Type"); 273 followTypeMenu.setEnabled(false); 274 followTypeMenu.addActionListener(this); 275 menu.add(followTypeMenu); 276 setJMenuBar(menuBar); 277 278 validate(); 279 treeView.expandPath(new TreePath(((DefaultMutableTreeNode)treeModel.getRoot()).getPath())); 280 281 treeView.addMouseListener((MouseListener)this); 282 contentTable.addMouseListener((MouseListener)this); 283 setName("IRBrowser"); 288 setName("IRBrowser"); 289 initConnections(); 290 } 293 294 private static void usage() 295 { 296 System.err.println("usage: IRBrowser [ IOR | -f <ior_file ]"); 297 System.exit(1); 298 } 299 300 301 304 305 public static void main(String args[]) 306 { 307 IRBrowser test = null; 308 String ior = null; 309 310 if( args.length > 2 ) 311 { 312 usage(); 313 } 314 else if( args.length == 2 && args[0].equals("-f")) 315 { 316 try 317 { 318 java.io.BufferedReader in = 319 new java.io.BufferedReader (new java.io.FileReader ( args[1] ) ); 320 ior = in.readLine(); 321 while (ior.indexOf("IOR:") != 0) 322 ior = in.readLine(); 323 in.close(); 324 } 325 catch ( java.io.IOException io ) 326 { 327 io.printStackTrace(); 328 usage(); 329 } 330 test = new IRBrowser(ior); 331 } 332 else if( args.length == 1 ) 333 { 334 test = new IRBrowser(args[0]); 335 } 336 else 337 { 338 test = new IRBrowser(); 339 } 340 test.show(); 341 return; 342 } 343 344 public void mouseClicked(MouseEvent event) 345 { 346 javax.swing.tree.DefaultMutableTreeNode treeNode = null; 347 if ( event.getComponent() == contentTable && 349 event.getClickCount() > 1 && 350 contentTable.getSelectedRow() != -1) 351 { 352 System.out.println("contentTable doubleClick"); 353 355 NodeMapper nodeMapper = 356 (NodeMapper)contentTable.getModel().getValueAt(contentTable.getSelectedRow(),0); 357 TypeSystemNode typeSystemNode = nodeMapper.getNode(); 358 359 if (typeSystemNode instanceof AbstractContainer) 360 { 361 treeNode = 362 (DefaultMutableTreeNode)typeSystemNode.getModelRepresentant(treeModel); 363 } 364 365 if (typeSystemNode instanceof TypeAssociator) 366 { 367 TypeSystemNode assTypeNode = 368 ((TypeAssociator)typeSystemNode).getAssociatedTypeSystemNode(); 369 if (assTypeNode.getModelRepresentant(treeModel) != null) 370 { 371 treeNode = 372 (DefaultMutableTreeNode)assTypeNode.getModelRepresentant(treeModel); 373 } 374 } 375 if ( treeNode!=null ) 376 { 377 379 System.out.println("expanding Tree: "+treeNode); 380 DefaultTreeModel treeModel = 381 (DefaultTreeModel)treeView.getModel(); 382 TreePath fullTreePath = 383 new TreePath(treeModel.getPathToRoot(treeNode)); 384 385 treeView.scrollPathToVisible(fullTreePath); 386 treeView.setSelectionPath(fullTreePath); 388 treeView.validate(); 389 } 390 } 391 } 392 393 public void mouseEntered(MouseEvent event) {} 394 public void mouseExited(MouseEvent event){} 395 public void mousePressed(MouseEvent event){} 396 public void mouseReleased(MouseEvent event){} 397 398 404 405 public void setSelectedNode (TypeSystemNode node ) 406 { 407 setTitle(title + " - " + node.getAbsoluteName()); 409 textArea.setText(node.description()); 410 if (node instanceof TypeAssociator) 411 { 412 followTypeMenu.setEnabled(true); 413 } 414 else 415 { 416 followTypeMenu.setEnabled(false); 417 } 418 } 419 420 421 423 424 public void valueChanged (ListSelectionEvent e ) 425 { 426 TypeSystemNode node; 429 if (contentTable.getSelectedRow() != -1) 430 { 431 NodeMapper nodeMapper = 432 (NodeMapper)contentTable.getModel().getValueAt(contentTable.getSelectedRow(),0); 433 434 if ((node = ((TypeSystemNode)nodeMapper.getNode())) != null) 435 { 436 setSelectedNode(node); 437 } 438 } 439 } 440 441 443 444 public void valueChanged (TreeSelectionEvent e ) 445 { 446 DefaultMutableTreeNode treeNode = 448 (DefaultMutableTreeNode)e.getPath().getLastPathComponent(); 449 450 TypeSystemNode node = 451 (TypeSystemNode)treeNode.getUserObject(); 452 453 contentTable.setModel(typeSystem.getTableModel(treeNode)); 454 contentTable.clearSelection(); 455 TableColumnModel tabColMod = contentTable.getColumnModel(); 456 457 for (int i=0; i<contentTable.getColumnCount(); i++) 458 { 459 TableColumn tabCol = tabColMod.getColumn(i); 460 tabCol.setCellEditor( null ); 461 } 463 setSelectedNode(node); 464 contentTable.validate(); 465 treeView.validate(); 466 } 467 468 472 473 public void windowActivated(java.awt.event.WindowEvent e) { 474 } 479 480 484 485 486 487 public void windowClosed(java.awt.event.WindowEvent e) 488 { 489 System.exit(0); 491 495 } 496 497 501 502 503 public void windowClosing(java.awt.event.WindowEvent e) 504 { 505 if ((e.getSource() == this) ) 508 { 509 conn0(e); 510 } 511 } 514 515 519 520 521 public void windowDeactivated(java.awt.event.WindowEvent e) { 522 } 527 528 532 533 534 public void windowDeiconified(java.awt.event.WindowEvent e) { 535 } 540 541 545 546 547 public void windowIconified(java.awt.event.WindowEvent e) { 548 } 553 554 558 559 560 public void windowOpened(java.awt.event.WindowEvent e) 561 { 562 } 567 } 568 569 | Popular Tags |