View Javadoc
1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 11 package com.sun.xml.registry.client.browser; 12 13 import com.sun.xml.registry.client.browser.graph.JBGraphPanel; 14 15 import java.awt.*; 16 import java.awt.event.*; 17 18 import java.net.URL; 19 20 import java.util.ArrayList; 21 22 import javax.swing.*; 23 import javax.swing.event.*; 24 import javax.swing.plaf.FontUIResource; 25 import javax.swing.tree.*; 26 27 import javax.xml.registry.BulkResponse; 28 import javax.xml.registry.BusinessLifeCycleManager; 29 import javax.xml.registry.JAXRException; 30 import javax.xml.registry.JAXRResponse; 31 import javax.xml.registry.infomodel.ClassificationScheme; 32 import javax.xml.registry.infomodel.Concept; 33 import javax.xml.registry.infomodel.Key; 34 import javax.xml.registry.infomodel.RegistryObject; 35 36 import com.sun.xml.registry.client.browser.RegistryBrowser; 37 38 39 /*** 40 * A JTree that lists 41 * 42 * @author Jim Glennon 43 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 44 */ 45 public class ConceptsTree extends JTree implements java.beans.PropertyChangeListener { 46 47 /*** DOCUMENT ME! */ 48 JPopupMenu popup; 49 50 /*** DOCUMENT ME! */ 51 JMenuItem editMenuItem = null; 52 53 /*** DOCUMENT ME! */ 54 JMenuItem insertMenuItem = null; 55 56 /*** DOCUMENT ME! */ 57 JMenuItem removeMenuItem = null; 58 59 /*** DOCUMENT ME! */ 60 JMenuItem saveMenuItem = null; 61 62 /*** DOCUMENT ME! */ 63 JMenuItem browseMenuItem = null; 64 65 /*** DOCUMENT ME! */ 66 JMenuItem auditTrailMenuItem = null; 67 68 /*** DOCUMENT ME! */ 69 JMenuItem exportMenuItem = null; 70 71 /*** DOCUMENT ME! */ 72 JMenuItem retrieveMenuItem = null; 73 74 /*** DOCUMENT ME! */ 75 MouseListener popupListener; 76 77 private boolean editable = RegistryBrowser.getInstance().isAuthenticated(); 78 79 private static ConceptsTreeModel s_conceptsTreeModel = null; 80 81 /*** 82 * Class Constructor. 83 * 84 * @see 85 */ 86 public ConceptsTree(boolean updateOnCreate) { 87 if (s_conceptsTreeModel == null) { 88 s_conceptsTreeModel = new ConceptsTreeModel(updateOnCreate); 89 } 90 this.setModel(s_conceptsTreeModel); 91 92 setCellRenderer(new ConceptsTreeCellRenderer()); 93 setRootVisible(false); 94 setShowsRootHandles(true); 95 addTreeSelectionListener(new TreeSelectionListener() { 96 public void valueChanged(TreeSelectionEvent e) { 97 98 DefaultMutableTreeNode node = 99 (DefaultMutableTreeNode)getLastSelectedPathComponent(); 100 101 if (node == null) { 102 103 return; 104 } 105 106 Component c = 107 SwingUtilities.getRoot(ConceptsTree.this); 108 Cursor oldCursor = c.getCursor(); 109 RegistryBrowser.setWaitCursor(); 110 ((ConceptsTreeModel)getModel()).expandTree(node, 1); 111 RegistryBrowser.setDefaultCursor(); 112 } 113 }); 114 115 ((ConceptsTreeModel)getModel()).addTreeModelListener(new TreeModelListener() { 116 public void treeNodesChanged(TreeModelEvent e) { 117 } 118 119 public void treeNodesInserted(TreeModelEvent e) { 120 121 // expandPath(e.getTreePath()); 122 } 123 124 public void treeNodesRemoved(TreeModelEvent e) { 125 } 126 127 public void treeNodesStructureChanged(TreeModelEvent e) { 128 } 129 130 public void treeStructureChanged(TreeModelEvent e) { 131 } 132 }); 133 134 135 createPopup(); 136 137 //add lister authenticated bound property 138 RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_AUTHENTICATED, this); 139 140 setToolTipText("Classification Schemes"); 141 } 142 143 /*** Create popup menu for List */ 144 private void createPopup() { 145 // Create popup menu for table 146 popup = new JPopupMenu(); 147 148 if (editable) { 149 editMenuItem = new JMenuItem("Edit"); 150 } 151 else { 152 editMenuItem = new JMenuItem("Show Details"); 153 } 154 popup.add(editMenuItem); 155 insertMenuItem = new JMenuItem("Insert"); 156 popup.add(insertMenuItem); 157 removeMenuItem = new JMenuItem("Remove"); 158 popup.add(removeMenuItem); 159 saveMenuItem = new JMenuItem("Save"); 160 popup.add(saveMenuItem); 161 browseMenuItem = new JMenuItem("Browse"); 162 popup.add(browseMenuItem); 163 auditTrailMenuItem = new JMenuItem("Show Audit Trail"); 164 popup.add(auditTrailMenuItem); 165 exportMenuItem = new JMenuItem("Export"); 166 popup.add(exportMenuItem); 167 168 boolean authenticated = RegistryBrowser.getInstance().isAuthenticated(); 169 170 insertMenuItem.setVisible(authenticated); 171 removeMenuItem.setVisible(authenticated); 172 saveMenuItem.setVisible(authenticated); 173 174 editMenuItem.addActionListener(new ActionListener() { 175 public void actionPerformed(ActionEvent ae) { 176 editAction(); 177 } 178 }); 179 180 insertMenuItem.addActionListener(new ActionListener() { 181 public void actionPerformed(ActionEvent ae) { 182 insertAction(); 183 } 184 }); 185 186 removeMenuItem.addActionListener(new ActionListener() { 187 public void actionPerformed(ActionEvent ae) { 188 removeAction(); 189 } 190 }); 191 192 saveMenuItem.addActionListener(new ActionListener() { 193 public void actionPerformed(ActionEvent ae) { 194 saveAction(); 195 } 196 }); 197 198 browseMenuItem.addActionListener(new ActionListener() { 199 public void actionPerformed(ActionEvent ae) { 200 browseAction(); 201 } 202 }); 203 204 auditTrailMenuItem.addActionListener(new ActionListener() { 205 public void actionPerformed(ActionEvent ae) { 206 auditTrailAction(); 207 } 208 }); 209 210 exportMenuItem.addActionListener(new ActionListener() { 211 public void actionPerformed(ActionEvent ae) { 212 exportAction(); 213 } 214 }); 215 216 // Add listener to self so that I can bring up popup menus on right mouse click 217 popupListener = new PopupListener(); 218 addMouseListener(popupListener); 219 220 } 221 222 /*** 223 * DOCUMENT ME! 224 * 225 * @return DOCUMENT ME! 226 */ 227 public ArrayList getSelectedConcepts() { 228 229 ArrayList objects = new ArrayList(); 230 231 TreePath[] treePaths = getSelectionPaths(); 232 233 if (treePaths != null) { 234 235 NodeInfo nodeInfo = null; 236 237 for (int i = 0; i < treePaths.length; ++i) { 238 nodeInfo = 239 (NodeInfo)(((DefaultMutableTreeNode)treePaths[i] 240 .getLastPathComponent()).getUserObject()); 241 242 if (nodeInfo.obj instanceof Concept) { 243 objects.add((Concept)nodeInfo.obj); 244 } 245 } 246 } 247 248 return objects; 249 } 250 251 /*** 252 * DOCUMENT ME! 253 * 254 * @return DOCUMENT ME! 255 */ 256 public ArrayList getSelectedClassificationSchemes() { 257 258 ArrayList objects = new ArrayList(); 259 260 TreePath[] treePaths = getSelectionPaths(); 261 262 if (treePaths != null) { 263 264 NodeInfo nodeInfo = null; 265 266 for (int i = 0; i < treePaths.length; ++i) { 267 nodeInfo = 268 (NodeInfo)(((DefaultMutableTreeNode)treePaths[i] 269 .getLastPathComponent()).getUserObject()); 270 271 if (nodeInfo.obj instanceof ClassificationScheme) { 272 objects.add(nodeInfo.obj); 273 } 274 } 275 } 276 277 return objects; 278 } 279 280 /*** 281 * DOCUMENT ME! 282 * 283 * @return DOCUMENT ME! 284 */ 285 public ArrayList getSelectedObjects() { 286 287 ArrayList objects = new ArrayList(); 288 289 TreePath[] treePaths = getSelectionPaths(); 290 291 if (treePaths != null) { 292 293 NodeInfo nodeInfo = null; 294 295 for (int i = 0; i < treePaths.length; ++i) { 296 nodeInfo = 297 (NodeInfo)(((DefaultMutableTreeNode)treePaths[i] 298 .getLastPathComponent()).getUserObject()); 299 objects.add(nodeInfo.obj); 300 } 301 } 302 303 return objects; 304 } 305 306 /*** 307 * DOCUMENT ME! 308 */ 309 protected void editAction() { 310 RegistryBrowser.setWaitCursor(); 311 312 Object[] selectedObjects = getSelectedObjects().toArray(); 313 314 if (selectedObjects.length == 1) { 315 316 RegistryObject ro = (RegistryObject)selectedObjects[0]; 317 JBEditorDialog.showObjectDetails(this, ro, false, editable); 318 } else { 319 RegistryBrowser.displayError("Exactly one object must be selected in list for Edit action."); 320 } 321 322 RegistryBrowser.setDefaultCursor(); 323 } 324 325 /*** 326 * DOCUMENT ME! 327 */ 328 protected void insertAction() { 329 330 try { 331 RegistryBrowser.setWaitCursor(); 332 333 ArrayList selectedObjects = 334 getSelectedObjects(); 335 JAXRClient client = 336 RegistryBrowser.getInstance().getClient(); 337 BusinessLifeCycleManager lcm = 338 client.getBusinessLifeCycleManager(); 339 340 int size = selectedObjects.size(); 341 342 if (size == 0) { 343 344 //Add a new ClassificationScheme 345 ClassificationScheme scheme = 346 lcm.createClassificationScheme("Scheme Name (Change me)", 347 "Scheme description (Change me)"); 348 349 JBDialog dialog = 350 JBEditorDialog.showObjectDetails(this, scheme, true, editable); 351 352 if (dialog.getStatus() != JBDialog.OK_STATUS) { 353 354 return; 355 } 356 357 //Now add to tree 358 ((ConceptsTreeModel)getModel()) 359 .insertClassificationScheme(scheme); 360 } else if (size == 1) { 361 362 RegistryObject selectedObject = 363 (RegistryObject)selectedObjects.get(0); 364 365 Concept concept = 366 lcm.createConcept(selectedObject, 367 "Concept Name (Change me)", 368 "Value (Change me)"); 369 JBDialog dialog = 370 JBEditorDialog.showObjectDetails(this, concept, true, editable); 371 372 if (dialog.getStatus() != JBDialog.OK_STATUS) { 373 374 return; 375 } 376 377 TreePath[] treePaths = getSelectionPaths(); 378 DefaultMutableTreeNode parentNode = 379 (DefaultMutableTreeNode)treePaths[0] 380 .getLastPathComponent(); 381 382 ((ConceptsTreeModel)getModel()).insertConcept(concept, 383 parentNode); 384 } else { 385 RegistryBrowser.displayError("Exactly one object must be selected in list for Insert action."); 386 } 387 388 RegistryBrowser.setDefaultCursor(); 389 } catch (JAXRException e) { 390 RegistryBrowser.displayError(e); 391 } 392 } 393 394 /*** 395 * DOCUMENT ME! 396 */ 397 protected void removeAction() { 398 RegistryBrowser.setWaitCursor(); 399 400 ArrayList selectedObjects = getSelectedObjects(); 401 402 int size = selectedObjects.size(); 403 404 if (size >= 1) { 405 406 try { 407 408 ArrayList removeKeys = new ArrayList(); 409 410 for (int i = size - 1; i >= 0; i--) { 411 412 RegistryObject obj = 413 (RegistryObject)selectedObjects.get(i); 414 Key key = obj.getKey(); 415 removeKeys.add(key); 416 } 417 418 JAXRClient client = 419 RegistryBrowser.getInstance().getClient(); 420 BusinessLifeCycleManager lcm = 421 client.getBusinessLifeCycleManager(); 422 BulkResponse resp = 423 lcm.deleteObjects(removeKeys); 424 client.checkBulkResponse(resp); 425 426 if (resp.getStatus() == JAXRResponse.STATUS_SUCCESS) { 427 428 TreePath[] currentSelection = getSelectionPaths(); 429 430 if (currentSelection != null) { 431 432 for (int j = 0; j < currentSelection.length; 433 j++) { 434 435 DefaultMutableTreeNode currentNode = 436 (DefaultMutableTreeNode)(currentSelection[j] 437 .getLastPathComponent()); 438 MutableTreeNode parent = 439 (MutableTreeNode)(currentNode.getParent()); 440 441 if (parent != null) { 442 ((ConceptsTreeModel)getModel()) 443 .removeNodeFromParent(currentNode); 444 } 445 } 446 } 447 } 448 } catch (JAXRException e) { 449 RegistryBrowser.displayError(e); 450 } 451 } else { 452 RegistryBrowser.displayError("One or more objects must be selected in list for Remove action."); 453 } 454 455 RegistryBrowser.setDefaultCursor(); 456 } 457 458 /*** 459 * DOCUMENT ME! 460 */ 461 protected void saveAction() { 462 RegistryBrowser.setWaitCursor(); 463 464 ArrayList selectedObjects = getSelectedObjects(); 465 466 int size = selectedObjects.size(); 467 468 if (size >= 1) { 469 470 try { 471 472 JAXRClient client = 473 RegistryBrowser.getInstance().getClient(); 474 client.saveObjects(selectedObjects); 475 } catch (JAXRException e) { 476 RegistryBrowser.displayError(e); 477 } 478 } else { 479 RegistryBrowser.displayError("One or more objects must be selected in list for Save action."); 480 } 481 482 RegistryBrowser.setDefaultCursor(); 483 } 484 485 /*** 486 * DOCUMENT ME! 487 */ 488 protected void browseAction() { 489 RegistryBrowser.setWaitCursor(); 490 491 ArrayList selectedObjects = getSelectedObjects(); 492 493 int size = selectedObjects.size(); 494 495 if (size >= 1) { 496 497 Component parent = 498 SwingUtilities.getRoot(ConceptsTree.this); 499 500 if (parent instanceof JFrame) { 501 JBGraphPanel.browseObjects((JFrame)parent, selectedObjects, editable); 502 } else if (parent instanceof JDialog) { 503 JBGraphPanel.browseObjects((JDialog)parent, 504 selectedObjects, editable); 505 } 506 } else { 507 RegistryBrowser.displayError("One or more objects must be selected in list for Browse action."); 508 } 509 510 RegistryBrowser.setDefaultCursor(); 511 } 512 513 /*** 514 * DOCUMENT ME! 515 */ 516 protected void auditTrailAction() { 517 RegistryBrowser.setWaitCursor(); 518 519 ArrayList selectedObjects = getSelectedObjects(); 520 521 int size = selectedObjects.size(); 522 523 if (size == 1) { 524 525 RegistryObject ro = (RegistryObject)selectedObjects.get(0); 526 RegistryBrowser.showAuditTrail(ro); 527 } else { 528 RegistryBrowser.displayError("Exactly one object must be selected in list for Show Audit Trail action."); 529 } 530 531 RegistryBrowser.setDefaultCursor(); 532 } 533 534 /*** 535 * DOCUMENT ME! 536 */ 537 protected void exportAction() { 538 RegistryBrowser.setWaitCursor(); 539 540 ArrayList selectedObjects = getSelectedObjects(); 541 542 int size = selectedObjects.size(); 543 544 if (size >= 1) { 545 546 JAXRClient client = 547 RegistryBrowser.getInstance().getClient(); 548 client.exportObjects(selectedObjects); 549 } else { 550 RegistryBrowser.displayError("One or more objects must be selected in list for Export action."); 551 } 552 553 RegistryBrowser.setDefaultCursor(); 554 } 555 556 /*** 557 * DOCUMENT ME! 558 */ 559 private void showSelectedObjectDetails() { 560 561 ArrayList selectedObjects = getSelectedObjects(); 562 563 int size = selectedObjects.size(); 564 565 if (size == 1) { 566 567 RegistryObject ro = (RegistryObject)selectedObjects.get(0); 568 JBEditorDialog.showObjectDetails(this, ro, false, editable); 569 } 570 } 571 572 /*** 573 * DOCUMENT ME! 574 * 575 * @author $author$ 576 * @version $Revision: 1.21 $ 577 */ 578 public class ConceptsTreeCellRenderer extends JLabel 579 implements TreeCellRenderer { 580 581 /*** Is the value currently selected. */ 582 protected boolean selected; 583 584 // These two ivars will be made protected later. 585 586 /*** True if has focus. */ 587 private boolean hasFocus; 588 589 /*** True if draws focus border around icon as well. */ 590 private boolean drawsFocusBorderAroundIcon; 591 592 // Icons 593 594 /*** Icon used to show non-leaf nodes that aren't expanded. */ 595 protected transient Icon closedIcon; 596 597 /*** Icon used to show leaf nodes. */ 598 protected transient Icon leafIcon; 599 600 /*** Icon used to show non-leaf nodes that are expanded. */ 601 protected transient Icon openIcon; 602 603 // Colors 604 605 /*** Color to use for the foreground for selected nodes. */ 606 protected Color textSelectionColor; 607 608 /*** Color to use for the foreground for non-selected nodes. */ 609 protected Color textNonSelectionColor; 610 611 /*** Color to use for the background when a node is selected. */ 612 protected Color backgroundSelectionColor; 613 614 /*** 615 * Color to use for the background when the node isn't 616 * selected. 617 */ 618 protected Color backgroundNonSelectionColor; 619 620 /*** 621 * Color to use for the background when the node isn't 622 * selected. 623 */ 624 protected Color borderSelectionColor; 625 626 /*** DOCUMENT ME! */ 627 DefaultMutableTreeNode node = null; 628 629 /*** DOCUMENT ME! */ 630 Object obj = null; 631 632 /*** 633 * Returns a new instance of DefaultTreeCellRenderer. 634 * Alignment is set to left aligned. Icons and text color are 635 * determined from the UIManager. 636 */ 637 public ConceptsTreeCellRenderer() { 638 setHorizontalAlignment(JLabel.LEFT); 639 setTextSelectionColor(UIManager.getColor("Tree.selectionForeground")); 640 setTextNonSelectionColor(UIManager.getColor("Tree.textForeground")); 641 setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground")); 642 setBackgroundNonSelectionColor(UIManager.getColor("Tree.textBackground")); 643 setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor")); 644 645 Object value = 646 UIManager.get("Tree.drawsFocusBorderAroundIcon"); 647 648 drawsFocusBorderAroundIcon = ((value != null) 649 && ((Boolean)value) 650 .booleanValue()); 651 } 652 653 /*** 654 * Returns the default icon, for the current laf, that is used 655 * to represent non-leaf nodes that are expanded. 656 * 657 * @return DOCUMENT ME! 658 */ 659 public Icon getDefaultOpenIcon() { 660 661 return getConceptsTreeIcon(); 662 } 663 664 /*** 665 * Returns the default icon, for the current laf, that is used 666 * to represent non-leaf nodes that are not expanded. 667 * 668 * @return DOCUMENT ME! 669 */ 670 public Icon getDefaultClosedIcon() { 671 672 return getConceptsTreeIcon(); 673 } 674 675 /*** 676 * Returns the default icon, for the current laf, that is used 677 * to represent leaf nodes. 678 * 679 * @return DOCUMENT ME! 680 */ 681 public Icon getDefaultLeafIcon() { 682 683 return getConceptsTreeIcon(); 684 } 685 686 /*** 687 * Returns the icon used to represent non-leaf nodes that are 688 * expanded. 689 * 690 * @return DOCUMENT ME! 691 */ 692 public Icon getOpenIcon() { 693 694 return getConceptsTreeIcon(); 695 } 696 697 /*** 698 * Returns the icon used to represent non-leaf nodes that are 699 * not expanded. 700 * 701 * @return DOCUMENT ME! 702 */ 703 public Icon getClosedIcon() { 704 705 return getConceptsTreeIcon(); 706 } 707 708 /*** 709 * Returns the icon used to represent leaf nodes. 710 * 711 * @return DOCUMENT ME! 712 */ 713 public Icon getLeafIcon() { 714 715 return getConceptsTreeIcon(); 716 } 717 718 /*** 719 * Sets the color the text is drawn with when the node is 720 * selected. 721 * 722 * @param newColor DOCUMENT ME! 723 */ 724 public void setTextSelectionColor(Color newColor) { 725 textSelectionColor = newColor; 726 } 727 728 /*** 729 * Returns the color the text is drawn with when the node is 730 * selected. 731 * 732 * @return DOCUMENT ME! 733 */ 734 public Color getTextSelectionColor() { 735 736 return textSelectionColor; 737 } 738 739 /*** 740 * Sets the color the text is drawn with when the node isn't 741 * selected. 742 * 743 * @param newColor DOCUMENT ME! 744 */ 745 public void setTextNonSelectionColor(Color newColor) { 746 textNonSelectionColor = newColor; 747 } 748 749 /*** 750 * Returns the color the text is drawn with when the node isn't 751 * selected. 752 * 753 * @return DOCUMENT ME! 754 */ 755 public Color getTextNonSelectionColor() { 756 757 return textNonSelectionColor; 758 } 759 760 /*** 761 * Sets the color to use for the background if node is 762 * selected. 763 * 764 * @param newColor DOCUMENT ME! 765 */ 766 public void setBackgroundSelectionColor(Color newColor) { 767 backgroundSelectionColor = newColor; 768 } 769 770 /*** 771 * Returns the color to use for the background if node is 772 * selected. 773 * 774 * @return DOCUMENT ME! 775 */ 776 public Color getBackgroundSelectionColor() { 777 778 return backgroundSelectionColor; 779 } 780 781 /*** 782 * Sets the background color to be used for non selected nodes. 783 * 784 * @param newColor DOCUMENT ME! 785 */ 786 public void setBackgroundNonSelectionColor(Color newColor) { 787 backgroundNonSelectionColor = newColor; 788 } 789 790 /*** 791 * Returns the background color to be used for non selected 792 * nodes. 793 * 794 * @return DOCUMENT ME! 795 */ 796 public Color getBackgroundNonSelectionColor() { 797 798 return backgroundNonSelectionColor; 799 } 800 801 /*** 802 * Sets the color to use for the border. 803 * 804 * @param newColor DOCUMENT ME! 805 */ 806 public void setBorderSelectionColor(Color newColor) { 807 borderSelectionColor = newColor; 808 } 809 810 /*** 811 * Returns the color the border is drawn. 812 * 813 * @return DOCUMENT ME! 814 */ 815 public Color getBorderSelectionColor() { 816 817 return borderSelectionColor; 818 } 819 820 /*** 821 * Sublcassed to only accept the font if it isn't a 822 * FonUIResource 823 * 824 * @param font DOCUMENT ME! 825 */ 826 public void setFont(Font font) { 827 828 if (font instanceof FontUIResource) { 829 font = null; 830 } 831 832 super.setFont(font); 833 } 834 835 /*** 836 * Configures the renderer based on the passed in components. 837 * The value is set from messaging value with toString(). The 838 * foreground color is set based on the selection and the icon 839 * is set based on on leaf and expanded. 840 * 841 * @param tree DOCUMENT ME! 842 * @param value DOCUMENT ME! 843 * @param sel DOCUMENT ME! 844 * @param expanded DOCUMENT ME! 845 * @param leaf DOCUMENT ME! 846 * @param row DOCUMENT ME! 847 * @param hasFocus DOCUMENT ME! 848 * 849 * @return DOCUMENT ME! 850 */ 851 public Component getTreeCellRendererComponent(JTree tree, 852 Object value, 853 boolean sel, 854 boolean expanded, 855 boolean leaf, 856 int row, 857 boolean hasFocus) { 858 node = (DefaultMutableTreeNode)value; 859 860 ImageIcon icon = null; 861 String text = node.toString(); 862 863 if (node == getModel().getRoot()) { 864 setText(text); 865 866 return this; 867 } 868 869 obj = ((NodeInfo)node.getUserObject()).obj; 870 871 String stringValue = 872 tree.convertValueToText(value, sel, expanded, leaf, 873 row, hasFocus); 874 875 this.hasFocus = hasFocus; 876 877 setText(stringValue); 878 879 if (sel) { 880 setForeground(getTextSelectionColor()); 881 } else { 882 setForeground(getTextNonSelectionColor()); 883 } 884 885 // There needs to be a way to specify disabled icons. 886 if (!tree.isEnabled()) { 887 setEnabled(false); 888 889 if (leaf) { 890 setDisabledIcon(getLeafIcon()); 891 } else if (expanded) { 892 setDisabledIcon(getOpenIcon()); 893 } else { 894 setDisabledIcon(getClosedIcon()); 895 } 896 } else { 897 setEnabled(true); 898 899 if (leaf) { 900 setIcon(getLeafIcon()); 901 } else if (expanded) { 902 setIcon(getOpenIcon()); 903 } else { 904 setIcon(getClosedIcon()); 905 } 906 } 907 908 selected = sel; 909 910 return this; 911 } 912 913 /*** 914 * Paints the value. The background is filled based on 915 * selected. 916 * 917 * @param g DOCUMENT ME! 918 */ 919 public void paint(Graphics g) { 920 921 Color bColor; 922 923 if (selected) { 924 bColor = getBackgroundSelectionColor(); 925 } else { 926 bColor = getBackgroundNonSelectionColor(); 927 928 if (bColor == null) { 929 bColor = getBackground(); 930 } 931 } 932 933 int imageOffset = -1; 934 935 if (bColor != null) { 936 937 Icon currentI = getIcon(); 938 939 imageOffset = getLabelStart(); 940 g.setColor(bColor); 941 g.fillRect(imageOffset, 0, 942 getWidth() - 1 - imageOffset, getHeight()); 943 } 944 945 if (hasFocus) { 946 947 if (drawsFocusBorderAroundIcon) { 948 imageOffset = 0; 949 } else if (imageOffset == -1) { 950 imageOffset = getLabelStart(); 951 } 952 953 Color bsColor = getBorderSelectionColor(); 954 955 if (bsColor != null) { 956 g.setColor(bsColor); 957 g.drawRect(imageOffset, 0, 958 getWidth() - 1 - imageOffset, 959 getHeight() - 1); 960 } 961 } 962 963 super.paint(g); 964 } 965 966 /*** 967 * Method Declaration. 968 * 969 * @return 970 * 971 * @see 972 */ 973 private int getLabelStart() { 974 975 Icon currentI = getIcon(); 976 977 if ((currentI != null) && (getText() != null)) { 978 979 return currentI.getIconWidth() 980 + Math.max(0, getIconTextGap() - 1); 981 } 982 983 return 0; 984 } 985 986 /*** 987 * Overrides <code>JComponent.getPreferredSize</code> to return 988 * slightly wider preferred size value. 989 * 990 * @return DOCUMENT ME! 991 */ 992 public Dimension getPreferredSize() { 993 994 Dimension retDimension = super.getPreferredSize(); 995 996 if (retDimension != null) { 997 retDimension = 998 new Dimension(retDimension.width + 3, 999 retDimension.height); 1000 } 1001 1002 return retDimension; 1003 } 1004 1005 /*** 1006 * Method Declaration. 1007 * 1008 * @return 1009 * 1010 * @see 1011 */ 1012 Icon getConceptsTreeIcon() { 1013 1014 Icon icon = null; 1015 1016 URL url = null; 1017 1018 if (((NodeInfo)node.getUserObject()).loaded) { 1019 url = getClass().getClassLoader().getResource("icons/trfolder.gif"); 1020 } else { 1021 1022 //??Need to find a different icon. ripoff.gif is broken 1023 url = getClass().getClassLoader().getResource("icons/trfolder.gif"); 1024 } 1025 1026 icon = new ImageIcon(url); 1027 1028 return icon; 1029 } 1030 } 1031 1032 /*** 1033 * Class Declaration. 1034 * 1035 * @author 1036 * @version 1.9, 03/29/00 1037 * 1038 * @see 1039 */ 1040 class PopupListener extends MouseAdapter { 1041 1042 /*** 1043 * DOCUMENT ME! 1044 * 1045 * @param e DOCUMENT ME! 1046 */ 1047 public void mousePressed(MouseEvent e) { 1048 maybeShowPopup(e); 1049 1050 if (e.getClickCount() > 1) { 1051 showSelectedObjectDetails(); 1052 } 1053 } 1054 1055 /*** 1056 * DOCUMENT ME! 1057 * 1058 * @param e DOCUMENT ME! 1059 */ 1060 public void mouseReleased(MouseEvent e) { 1061 maybeShowPopup(e); 1062 } 1063 1064 /*** 1065 * DOCUMENT ME! 1066 * 1067 * @param e DOCUMENT ME! 1068 */ 1069 private void maybeShowPopup(MouseEvent e) { 1070 1071 if (e.isPopupTrigger()) { 1072 popup.show(e.getComponent(), e.getX(), e.getY()); 1073 } 1074 } 1075 } 1076 1077 public static void clearCache() { 1078 s_conceptsTreeModel = null; 1079 } 1080 1081 /*** 1082 * Listens to property changes in the bound property RegistryBrowser.PROPERTY_AUTHENTICATED. 1083 * Hides certain menuItems when user is unAuthenticated. 1084 */ 1085 public void propertyChange(java.beans.PropertyChangeEvent ev) { 1086 if (ev.getPropertyName().equals(RegistryBrowser.PROPERTY_AUTHENTICATED)) { 1087 1088 boolean authenticated = ((Boolean)ev.getNewValue()).booleanValue(); 1089 setEditable(editable); 1090 1091 } 1092 } 1093 1094 /*** 1095 * Sets whether this dialog is read-only or editable. 1096 */ 1097 public void setEditable(boolean editable) { 1098 this.editable = editable; 1099 createPopup(); 1100 } 1101 1102 /*** 1103 * Tells whether this dialog is read-only or editable. 1104 */ 1105 public boolean isEditable() { 1106 return editable; 1107 } 1108 1109 }

This page was automatically generated by Maven